求大神...
<!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>可見(jiàn)性篩選選擇器</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">
function show (ele) {
if (ele instanceof jQuery) {
$("#show").html('元素的長(zhǎng)度的 = ' + ele.length)
} else {
document.write(ele+' 不是jQuery對(duì)象')
}
}
</script>
? ? <script type="text/javascript">
? ? ? ? //查找id = div1的DOM元素,是否可見(jiàn)
? ? ? ? show($("#div1:visible"));
? ? </script>
? ? <script type="text/javascript">
? ? //查找id = div2的DOM元素,是否可見(jiàn)
? ? show($("#div2:visible"));
? ? </script>
? ? <script type="text/javascript">
? ? //查找id = div3的DOM元素,是否可見(jiàn)
? ? show($("#div3:visible"));
? ? </script>
? ? <script type="text/javascript">
? ? //查找id = div1的DOM元素,是否隱藏
? ? show($("#div1:hidden"));
? ? </script>
? ? <script type="text/javascript">
? ? //查找id = div2的DOM元素,是否隱藏
? ? show($("#div2:hidden"));
? ? </script>
? ? <script type="text/javascript">
? ? //查找id = div3的DOM元素,是否隱藏
? ? show($('#div3:hidden'));
? ? </script>
</body>
</html>
這個(gè)里在慕課的右邊只顯示了第一個(gè)?
<script type="text/javascript">
? ? ? ? //查找id = div1的DOM元素,是否可見(jiàn)
? ? ? ? show($("#div1:visible"));
? ? </script>
后面的script都沒(méi)有顯示
2016-09-09
$("#show").html('元素的長(zhǎng)度的 = ' + ele.length)注意這一句,用的是 ?.html( ) 的方法把內(nèi)容寫(xiě)入。當(dāng)用該方法設(shè)置一個(gè)值時(shí),它會(huì)覆蓋所有匹配的元素的內(nèi)容。注意是“覆蓋”,在這里是顯示在id=show的元素($('#show')可知)中,因?yàn)槟忝看味际窃谕粋€(gè)地方進(jìn)行顯示,后一次的內(nèi)容會(huì)覆蓋前一次的,和js中的document.write( )類似的感覺(jué)。新手,歡迎指正交流?
2016-09-07
下面寫(xiě)的這個(gè)覆蓋了上面寫(xiě)的這條類似的語(yǔ)句,你輸入一個(gè)?show($("#div3:visible")); 元素的長(zhǎng)度就會(huì)變成1,就可以證明這一點(diǎn)了
2016-09-07
js腳本不是這樣寫(xiě)的。。。。。
<script type="text/javascript">
? ?這里面可以包含所有的js代碼,不用如你這樣一段就寫(xiě)一句
? ? </script>