Javascript 复选框 onChange [英] Javascript checkbox onChange
本文介绍了Javascript 复选框 onChange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在表单中有一个复选框,我希望它根据以下场景工作:
I have a checkbox in a form and I'd like it to work according to following scenario:
- 如果有人检查它,文本字段的值 (
totalCost
) 应设置为10
. - 然后,如果我返回并取消选中它,函数
calculate()
根据表单中的其他参数设置totalCost
的值.
- if someone checks it, the value of a textfield (
totalCost
) should be set to10
. - then, if I go back and uncheck it, a function
calculate()
sets the value oftotalCost
according to other parameters in the form.
所以基本上,我需要的部分是,当我选中复选框时,我会做一件事,当我取消选中它时,我会做另一件事.
So basically, I need the part where, when I check the checkbox I do one thing and when I uncheck it, I do another.
推荐答案
function calc()
{
if (document.getElementById('xxx').checked)
{
document.getElementById('totalCost').value = 10;
} else {
calculate();
}
}
HTML
<input type="checkbox" id="xxx" name="xxx" onclick="calc();"/>
这篇关于Javascript 复选框 onChange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文