html如何用checkbox 控制文本框中的内容.

来源:百度知道 编辑:UC知道 时间:2024/07/01 04:02:58
我希望有个checkbox,选中时,文本框中显示1,取消选中时,文本框中内容取消,怎么做?
应该是个script,应该怎么写?

试试是不是你想要的?
<script language=javascript>
function check(){
if(cbx.checked==true){
document.getElementById("show").value="1";
}else{
document.getElementById("show").value="";

}
}
</script>
<html>
<body>
<input type=checkbox id="cbx" onclick="check()"><input type="text" id="show">
</body>
</html>

你可以用个if语句来控制,当checkbox选中则textbox显示1如果checkbox没有选中textbox为空