JavaScript第一篇之實現按鈕全選、功能_javascript技巧

來源:互聯網
上載者:User

   1、建立一個文檔(用NotePad軟體,為了使得在瀏覽器中開啟不是亂碼,在軟體的檔案出找到編碼,將其修改為UTF-8編碼。或者點擊Google瀏覽器中的右上方的三條杠,選擇更多工具->編碼->UTF-8),將其重新命名(例:第一個java script.html   註:一定要把副檔名改為.html)。

   2、將其用記事本的格式開啟,進行編寫。

   3、以下是編寫的“按鈕全選的實現”的相關代碼:

<html><head><title> 全選按鈕的實現 </title></head><body><div><input type="checkbox" id="chkAll" onclick="checkAll(this)" />全選</div><div><input type="checkbox" name="chk"/>選項1</div><div><input type="checkbox" name="chk"/>選項2</div><div><input type="checkbox" name="chk"/>選項3</div><div><input type="checkbox" name="chk"/>選項4</div><input type="checkbox" name="chk"/>選項5</div></body><script>//全選function checkAll(e){var t=document.getElementsByName("chk");alert(t.length);for(var i=0;i<t.length;i++){t[i].checked=document.getElementById("chkAll").checked;}}</script></html>

  4、截圖為:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.