我有以下表格:
<form action="" method="get">
<input name="form1" type="radio" onclick="document.forms[0].testbox.value='0.00'; "/>
<input name="form1" type="radio" onclick="document.forms[0].testbox.value='1.00'; "/>
<input name="" type="checkbox" value="" onclick="document.forms[0].testbox2.value='1.00'; "/>
<input name="testbox" type="text" value="0.00"/>
<input name="testbox2" type="text" value="0.00"/>
</form>单选按钮更改时,文本框中的值也会从0.00到1.00变回1.00,依此类推。
我想用勾选/复选框做同样的事情-当testbox2中的点击值应该变成1.00时,当未点击时应该回到0.00时。
同样的onclick编码不起作用吗?想法?
谢谢
下面的评论尝试了这一点。却不能工作??
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function checkboxClick() {
var textbox = document.forms[0].testbox2;
textbox.value = (textbox.value == 0) ? '1.00' : '0.00';
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<form action="" method="get">
<input name="form1" type="radio" onclick="document.forms[0].testbox.value='0.00'; "/>
<input name="form1" type="radio" onclick="document.forms[0].testbox.value='1.00'; "/>
<input name="" type="checkbox" value="" onclick="document.forms[0].testbox2.value='1.00'; "/>
<input name="testbox" type="text" />
<input name="testbox2" type="text" value="0.00"/>
</form>
<body>
</body>
</html>忘记将此更改添加到onclick,如下所示..谢谢。。完美..。
发布于 2011-09-05 11:05:57
您需要在0和1之间切换该值。您所在的onclick只是将文本框设置为1.00。
<script>
function checkboxClick() {
var textbox = document.forms[0].testbox2;
textbox.value = (textbox.value == 0) ? '1.00' : '0.00';
}
</script>
<form method='get' action='#'>
<input name='testbox2' value='0.00'>
<input type='checkbox' onclick='checkboxClick()'>
</form>https://stackoverflow.com/questions/7303524
复制相似问题