如何选中禁用/启用带复选框的按钮 [英] How to disable/enable a button with a checkbox if checked

查看:109
本文介绍了如何选中禁用/启用带复选框的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个脚本,可以与HTML代码一起使用,以在复选框被选中或取消选中时禁用/启用按钮,

< input type =submitname =sendNewSmsclass =inputButtonid =sendNewSmsvalue =Send/>



请好朋友,我不是说在检查时禁用按钮,而是相反。 解决方案

brbcoding已经能够帮助我使用我需要的适当编码,这里是它$ / b>
$ b

HTML

 < input type =checkboxid =checkme/> 
< input type =submitname =sendNewSmsclass =inputButtondisabled =disabledid =sendNewSmsvalue =Send/>

Javascript

  var checker = document.getElementById('checkme'); 
var sendbtn = document.getElementById('sendNewSms');
//当未选中或检查时,运行函数
checker.onchange = function(){
if(this.checked){
sendbtn.disabled = false;
} else {
sendbtn.disabled = true;
}

}


Please i need a script that can work with the HTML code bellow to disable/enable the button when a checkbox is checked or unchecked,

<input type="submit" name="sendNewSms" class="inputButton" id="sendNewSms" value=" Send " />

please pals i don't mean the button to be disabled when checked, but rather the other way round.

解决方案

brbcoding have been able to help me with the appropriate coding i needed, here is it

HTML

<input type="checkbox" id="checkme"/>
  <input type="submit" name="sendNewSms" class="inputButton" disabled="disabled" id="sendNewSms" value=" Send " />

Javascript

 var checker = document.getElementById('checkme');
 var sendbtn = document.getElementById('sendNewSms');
 // when unchecked or checked, run the function
 checker.onchange = function(){
if(this.checked){
    sendbtn.disabled = false;
} else {
    sendbtn.disabled = true;
}

}

这篇关于如何选中禁用/启用带复选框的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆