為什么會顯示不是JQ對象,不是已經(jīng)用$變成JQ對象了嗎?為什么會顯示不是JQ對象,不是已經(jīng)用$變成JQ對象了嗎?為什么會顯示不是JQ對象,不是已經(jīng)用$變成JQ對象了嗎?
為什么會顯示不是JQ對象,不是已經(jīng)用$變成JQ對象了嗎?
<!DOCTYPE html>
<html>
<head>
? ? <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
? ? <title></title>
? ? <link rel="stylesheet" href="imooc.css" type="text/css">
? ? <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
</head>
<body>
? ? <h2>可見性篩選選擇器</h2>
? ? <h3>:visible/:hidden</h3>
? ? <div class="left">
? ? ? ? <div class="div">
? ? ? ? ? ? <a>display</a>
? ? ? ? ? ? <p id="div1" style="display:none;">display</p>
? ? ? ? </div>
? ? ? ? <div class="div">
? ? ? ? ? ? <a>width</a>
? ? ? ? ? ? <a>height</a>
? ? ? ? ? ? <p id="div2" style="width:0;height:0">width/height</p>
? ? ? ? </div>
? ? ? ? <div class="div">
? ? ? ? ? ? <a>visibility</a>
? ? ? ? ? ? <a>opacity</a>
? ? ? ? ? ? <p id="div3" style="visibility:hidden;opacity:0">visibility</p>
? ? ? ? </div>
? ? </div>
? ? <p id="show"></p>
<script type="text/javascript">
var count = 0;
function show (ele) {
if (ele instanceof jQuery) {
$("#show").html('元素的長度的 = ' + ele.length);
count++;
}?
else {
alert(ele+' 不是jQuery對象');
count++;
}
alert(count);
}
</script>
</body>
</html>
? ? <script type="text/javascript">
? ? //查找id = div1的DOM元素,是否可見
? ? show($('#div1:visible') );
? ? </script>
為什么會顯示不是JQ對象,不是已經(jīng)用$變成JQ對象了嗎?
之后我在方法里加一個count,最后一次count顯示4,大家?guī)蛶兔忉屢幌聻槭裁矗?/p>
var count = 0;
function show (ele) {
if (ele instanceof jQuery) {
$("#show").html('元素的長度的 = ' + ele.length);
count++;
}?
else {
alert(ele+' 不是jQuery對象');
count++;
}
alert(count);
}
2017-02-27
首先代碼還是不全只給了第一個SHOW()的 另外其他的如果你沒有去修改原本的代碼 那肯定會提示你不是JQ對象,你需要先確認到底是不是這第一個SHOW()報的不是JQ對象,我直接復制你這句代碼,沒有問題不會提示非JQ對象至于總共4次,其實應該不止4次,你通過 show()調(diào)用了幾次 他就是幾
2017-02-17
代碼請貼全,你這div1鬼知道哪來的