html复选框一个选项,是和否 [英] html checkbox one option with yes and no

查看:133
本文介绍了html复选框一个选项,是和否的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Team,

我编写的代码如下:

Hello Team,
I have wrote the code as follows :

<div class="input-append">
            <label>
                Processed :</label>
            <input type="checkbox" id="processedCheckBox" checked="checked" />
        </div>





我想要的是

在一个复选框中,

Bydefault复选框将被选中,表示是

如果我从复选框中取出已选中的复选框,则表示没有。

我想把值设为是和否

那么如何做到这一点。

请建议

谢谢

Harshal。



What i want is
In One Checkbox,
Bydefault checkbox will be checked that means Yes
If i removed the checked from Checkbox that means No.
I want to put the value Yes and No
So how to do this.
Please Advice
Thanks
Harshal.

推荐答案

HTML中复选框的正确格式是......

The proper format of checkbox in HTML is...
<input type="chekbox" />
<input type="chekbox" checked="" />



...分别为未选中/已检查.. 。

如果你想把复选框的状态改为是/否字符串你必须使用这样的一些JavaScript:


...for unchecked/checked respectively...
If you want to turn the state of the checkbox to yes/no string yous have to use some JavaScript like this:

var ans = document.getElementById('checkbox_id').checked ? 'yes' : 'no';


尝试使用JavaScript:

Try this with JavaScript:
<!DOCTYPE html>
<html>
<script>
function getCheckboxStatus(){
   var status = document.getElementById("processedCheckBox").checked;
   if (status) {
      alert("Yes");
   } else {
      alert("No");
   }
}
</script>
<body>
<div class="input-append">
     <label for="processedCheckBox">Processed :</label>
     <input type="checkbox" id="processedCheckBox" checked onchange="getCheckboxStatus()">
</div>
</body>
</html>


这篇关于html复选框一个选项,是和否的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆