JS實現點擊複選框將按鈕或文字框變為灰色停用方法_javascript技巧

來源:互聯網
上載者:User

本文執行個體講述了JS實現點擊複選框將按鈕或文字框變為灰色停用方法。分享給大家供大家參考。具體如下:

在註冊時候經常會看不到,如果不點擊閱讀註冊許可的話,提交按鈕是灰色的,失效不能提交,必須點它一下,這個JS代碼就是實現這樣一個功能,只有你點擊了確認提交,下邊的按鈕才生效。

運行效果如下圖所示:

具體代碼如下:

<html><head><title>點擊複選框按鈕變為不可用</title></head><script>var checkobjfunction agreesubmit(el){checkobj=elif (document.all||document.getElementById){for (i=0;i<checkobj.form.length;i++){ var tempobj=checkobj.form.elements[i]if(tempobj.type.toLowerCase()=="submit")tempobj.disabled=!checkobj.checked}}}function defaultagree(el){if (!document.all && !document.getElementById){if (window.checkobj && checkobj.checked)return trueelse{alert("Please read/accept terms to submit form")return false}}}</script><body><form name="agreeform" onSubmit="return defaultagree(this)"><input name="agreecheck" type="checkbox" onClick="agreesubmit(this)"><b>你確認要提交?</b><br><input type="Submit" value="我一定要提交" disabled></form><script>document.forms.agreeform.agreecheck.checked=false</script></body></html>

希望本文所述對大家的javascript程式設計有所協助。

聯繫我們

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