84669 Lernen von Personen
152542 Lernen von Personen
20005 Lernen von Personen
5487 Lernen von Personen
7821 Lernen von Personen
359900 Lernen von Personen
3350 Lernen von Personen
180660 Lernen von Personen
48569 Lernen von Personen
18603 Lernen von Personen
40936 Lernen von Personen
1549 Lernen von Personen
1183 Lernen von Personen
32909 Lernen von Personen
jQuery怎么检测某个元素是否存在?
jQuery怎么检测某个元素是否存在?-PHP中文网问答-jQuery怎么检测某个元素是否存在?-PHP中文网问答
围观一下哦,学习一下。
使用$(selector)可以获得匹配元素集合,而匹配元素集合的length属性可以获得集合中匹配元素的个数,所以只要判断length属性值是否为零,就可以判断元素是否存在。代码实例如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>PHP中文网</title> <script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js?1.1.9"></script> <script type="text/javascript"> $(document).ready(function(){ $("#check").click(function(){ if($(".mytest").length>0){ alert("此元素存在"); } }) }) </script> <body> <ul> <li>太阳出来了</li> <li>PHP中文网</li> <li class="mytest">p+css教程</li> </ul> <button id="check">点击检测</button> </body> </html>
如果集合中元素的数量大于零,那么元素存在,否则指定元素不存在。
jQuery怎么检测某个元素是否存在?-PHP中文网问答-jQuery怎么检测某个元素是否存在?-PHP中文网问答
围观一下哦,学习一下。
使用$(selector)可以获得匹配元素集合,而匹配元素集合的length属性可以获得集合中匹配元素的个数,所以只要判断length属性值是否为零,就可以判断元素是否存在。代码实例如下:
如果集合中元素的数量大于零,那么元素存在,否则指定元素不存在。