如何在javascript中显示所选的复选框值 [英] how to display the selected check box value in javascript
本文介绍了如何在javascript中显示所选的复选框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我点击打印按钮,我想显示所选的复选框值
I want to dispaly the selected check box value if i click on the print button
这里是我的代码
<! DOCTYPE html>
<head>
<script type="text/javascript">
function checkbox()
{
var bk=document.getElementById("bk").value;;
var cer=document.getElementById("cr").value;
document.writeln(" " + bk );
document.write(" " + cer);
}
</script>
</head>
<body>
<form>
<input type="checkbox" id="bk" name="vehicle" value="Bike">I have a bike<br></br>
<input type="checkbox" id="cr" name="vehicle" value="Car">I have a car<br></br>
<input type="submit" value=" Print " size="30" onClick="checkbox()">
</form>
</body>
</html>
如果我选择自行车复选框并单击打印按钮,它应显示唯一的自行车。
If I select Bike check box and click on print button, it should display the only Bike.
推荐答案
我已经编辑了你的代码并根据你的需要进行了修改。请仔细阅读代码。
i have edited your code and modified according to your needs. please go through the code.
<! DOCTYPE html>
<head>
<script type="text/javascript">
function checkbox()
{
var bk=document.getElementById("bk").checked;;
var cer=document.getElementById("cr").checked;
if(bk) document.writeln(" Bike");
if(cer) document.write(" Car");
return false;
}
</script>
</head>
<body>
<form>
<input type="checkbox" id="bk" name="vehicle" value="Bike">I have a bike<br></br>
<input type="checkbox" id="cr" name="vehicle" value="Car">I have a car<br></br>
<input type="submit" value=" Print " size="30" onClick="return checkbox();">
</form>
</body>
</html>
这篇关于如何在javascript中显示所选的复选框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文