首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Checkbox ticked value to go to textbox (切换方式类似)

Checkbox ticked value to go to textbox (切换方式类似)
EN

Stack Overflow用户
提问于 2011-09-05 10:55:42
回答 1查看 2.7K关注 0票数 0

我有以下表格:

代码语言:javascript
复制
<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编码不起作用吗?想法?

谢谢

下面的评论尝试了这一点。却不能工作??

代码语言:javascript
复制
 <!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,如下所示..谢谢。。完美..。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-05 11:05:57

您需要在0和1之间切换该值。您所在的onclick只是将文本框设置为1.00。

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7303524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档