简体   繁体   English

这个jQuery代码是什么意思?

[英]What does this jQuery code mean?

Can anyone explain the meaning of this code? 谁能解释这段代码的含义?

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

如果我猜测的返回data是AJAX调用,其属性result未设置为false0 ,则获取具有id intlist的无序列表,并在返回数据的content属性中附加任何content

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 此代码基本上是在检查是否存在某些数据if(data.result) ,然后将数据内容附加到ID为intlistulintlist

So if you had an UL as follows: 因此,如果您具有以下UL:

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

Then the jQuery code would be inserting the result of data.content to this list. 然后jQuery代码将data.content的结果插入到此列表中。

In jQuery you can use CSS selectors to gain access to the elements you want. 在jQuery中,您可以使用CSS选择器来访问所需的元素。 If you were to do $('ul') this would give you access to all ul's on the page. 如果您要执行$('ul')这将使您可以访问页面上的所有ul。 If you were to do $('#intlist') this would give you access to an element with an id of "intlist". 如果您要执行$('#intlist')可以访问ID为“ intlist”的元素。 You can combine these selectors as in your code above so that $('ul#intlist') is getting an ul with the id of "intlist". 您可以像上面的代码中那样组合这些选择器,以便$('ul#intlist')获得ID为“ intlist”的ul。 The hash # symbol is used to obtain items by Id. 井号#符号用于通过ID获取项目。

You can read more about jQuerys append() method here: http://api.jquery.com/append/ 您可以在此处阅读有关jQuerys append()方法的更多信息: http ://api.jquery.com/append/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM