“checkbox”和“select”對象在javascript和jquery的操作差異做了整理

來源:互聯網
上載者:User

標籤:lis   style   top   checked   ref   jquery   賦值   otto   target   

checkbox

checkbox在javascript和jquery中選中和取消的方法

Javascript:

document.getElementById("myCheck").checked=true

document.getElementById("myCheck").checked=false

Jquery:

$("#myCheck").attr("checked","checked");

$("#myCheck").removeAttr("checked");//取消全選 

 

select

select在javascript和jquery中擷取option值

Javascript:

var mylist=document.getElementById("myList");

擷取id mylist.value 

擷取選項值mylist.options[mylist.selectedIndex].text

Jquery:

擷取id $("#myList").val()

擷取選項值 $("#myList option:selected").text()

 

select在javascript和jquery中賦值

Javascript:

var mylist=document.getElementById("myList");

mylist.options[1].selected=true;

Jquery:

$("#myList").get(0).options[2].selected = true;


原文地址http://haiqiancun.com/bbs/bbsPage/0/detail/297e9e7946a599780146a5a38dde0003/1/20140623141930




“checkbox”和“select”對象在javascript和jquery的操作差異做了整理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.