开发者

What does this jQuery code mean?

Can anyone explain the开发者_运维百科 meaning of this code?

if (data.result) {
    $('ul#intlist').append(data.content);
}


if the returning data from what I'm guessing is an AJAX-call has a property result which is not set to false or 0, then get the unordered list with an id intlist and append whatever is in the content property of the returning data.


This code is basically checking whether some data exists if(data.result) and then appends the content of the data to the end of an ul with an ID of intlist

So if you had an UL as follows:

<ul id="intlist">
   ...
</ul>

Then the jQuery code would be inserting the result of data.content to this list.

In jQuery you can use CSS selectors to gain access to the elements you want. If you were to do $('ul') this would give you access to all ul's on the page. If you were to do $('#intlist') this would give you access to an element with an id of "intlist". You can combine these selectors as in your code above so that $('ul#intlist') is getting an ul with the id of "intlist". The hash # symbol is used to obtain items by Id.

You can read more about jQuerys append() method here: http://api.jquery.com/append/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜