亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

jQuery標(biāo)簽包含內(nèi)容操作

標(biāo)簽包含內(nèi)容操作

利用javascript操作:

  • dvnode.innerHTML?獲得div包含的信息

  • dvnode.innerHTML?= XXX; ?設(shè)置div包含的內(nèi)容

注:innerHTML不是w3c標(biāo)準(zhǔn)技術(shù),許多瀏覽器對其有支持而已

利用jquery操作:

  • $().html(); ?? ?//獲得節(jié)點包含的信息

  • $().html(信息); ? //設(shè)置節(jié)點包含的內(nèi)容

  • $().text(); ? //獲得節(jié)點包含的“文本字符串信息”內(nèi)容

  • $().text(信息); ?//設(shè)置節(jié)點包含的內(nèi)容(有html標(biāo)簽就把“><”符號變?yōu)榉枌嶓w)

<!DOCTYPE html>
<html>
    <head>
        <title>php.cn</title>
        <meta charset="utf-8" />
        <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
        <script>
           function f1(){
            alert($('div').html());
            alert($('div').text());
            }
            function f2(){

                $('div').text("這里是php中文網(wǎng)");
            } 
        </script>
    </head>
    <body>
        <div>歡迎 <p>大家 <span>學(xué)習(xí)jQuery</span></p></div>

        <input type="button" value="獲取" onclick="f1()" />
        <input type="button" value="設(shè)置" onclick="f2()" /> 
    </body>
</html>



html() 和 text()方法的區(qū)別:

①?獲取內(nèi)容

前者可以獲取html標(biāo)簽?和 普通字符串內(nèi)容

后者只獲取普通字符串內(nèi)容

②?設(shè)置內(nèi)容

前者可以設(shè)置html標(biāo)簽?和 普通字符串內(nèi)容

后者只設(shè)置普通字符串內(nèi)容,如果內(nèi)容里邊有tag標(biāo)簽內(nèi)容,就把其中的”<”“>”符號轉(zhuǎn)變?yōu)榉枌嶓w <-----$lt;? >----> ? 空格------  

以上兩種操作(獲取/設(shè)置)如果針對的操作內(nèi)容是純字符串內(nèi)容,則使用效果一致。


繼續(xù)學(xué)習(xí)
||
<!DOCTYPE html> <html> <head> <title>php.cn</title> <meta charset="utf-8" /> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> function f1(){ alert($('div').html()); alert($('div').text()); } function f2(){ $('div').text("這里是php中文網(wǎng)"); } </script> </head> <body> <div>歡迎 <p>大家 <span>學(xué)習(xí)jQuery</span></p></div> <input type="button" value="獲取" onclick="f1()" /> <input type="button" value="設(shè)置" onclick="f2()" /> </body> </html>
提交重置代碼