在单选按钮中显示布尔值 [英] Display Boolean value in radio button

查看:112
本文介绍了在单选按钮中显示布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下循环在视图中显示数据,我需要显示单选按钮的帮助.我的数据库中有 flag 字段,其值为0或1.我想在单选按钮中显示该值.

I have the following loop to display data in a view, I need help displaying radio button. I have flag field in my database it has value either 0 or 1. I want to display that in radio button.

@foreach (var item in prodInfo)
{
    @item.flag
}

推荐答案

您可以执行以下操作:

var n = 0; // set your bool value here 0/1
if(n===1)
{
 document.getElementById("yourRadiobtn").checked = true;
}
else
{
 document.getElementById("yourRadiobtn").checked = false;
}

  <input type="radio" name="colors" id="yourRadiobtn">Item

如果您使用的是布尔类型,则

If you're using a bool type then

var  n = false ; // set your bool value here (true/false)
if(n === true)
{
 document.getElementById("yourRadiobtn").checked = true;
}
else
{
 document.getElementById("yourRadiobtn").checked = false;
}

  <input type="radio" name="colors" id="yourRadiobtn">Item

这篇关于在单选按钮中显示布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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