<input type="radio" name="p_isvoice" class="radio" value="有" /> 有
<input type="radio" name="p_isvoice" class="radio" value="无"/> 无
这里是一个文本框的,在页面加载时,就将数据字段显示在input里了
<input type="text" id="expenseName" name="expenseName" style="width:200px" />
$("#expenseName").val(json.expensename);
我使用C# + Oracle + jQuery
12 个解决方案
#1
<input type="radio" name="p_isvoice" class="radio" value="有" /> 有
<input type="radio" name="p_isvoice" class="radio" value="无" checked/> 无
<input type="radio" name="p_isvoice" class="radio" value="无" checked/> 无
#2
<input type="radio" name="p_isvoice" class="radio" value="有" checked="checked"/> 有
<input type="radio" name="p_isvoice" class="radio" value="无"/> 无
<input type="radio" name="p_isvoice" class="radio" value="无"/> 无
#3
不是这样的,我要的是:这个按钮的值,它在数据库中为“有”的话,页面加载后,就选中为有;如果数据库中这个值是“无”的话,它就选中"无"
#4
首先你数据库中要有个存放是否选中的值吧,比如有个字段checked 1选中 0没选中
如果按照json格式取出 obj:{checked:1}
if(obj.checked==1){
$('p_isvoice').checked=checked;
}
如果按照json格式取出 obj:{checked:1}
if(obj.checked==1){
$('p_isvoice').checked=checked;
}
#5
<input type="text" id="expenseName" name="expenseName" style="width:200px" />
<input type="radio" name="p_isvoice" class="radio" value="有" /> 有
<input type="radio" name="p_isvoice" class="radio" value="无" checked/> 无
$(function(){
var el = $("#expenseName");
el.val("有");
$(":radio[name='p_isvoice']").each(function(){
var $this = $(this);
if (el.val() === $this.val()){
$this.attr("checked", "checked");
}
})
})
#6
$(":radio[name='p_isvoice'][value='"+$("#expenseName").val()+"']").attr("checked", "checked");
#7
<html>
<head>
<title>JavaScript</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("input[name='p_isvoice'][value='有']").attr("checked","checked")
})
</script>
</head>
<body>
<input type="radio" name="p_isvoice" class="radio" value="有"/> 有
<input type="radio" name="p_isvoice" class="radio" value="无"/> 无
</body>
</html>
#8
if(json.expensename!="")
{
$("#expenseName").get(0).checked = "checked ";
}
{
$("#expenseName").get(0).checked = "checked ";
}
#9
josn 我没绑过 ,不过如果你的意思用$("#expenseName").val(json.expensename)可以绑定数据库的值的话,你可以用下面的方法试试看:
<input type="radio" name="p_isvoice" class="radio" value="有" checked="
<%# IsChecked($("#expenseName").val(json.expensename))%> />
//$("#expenseName").val(json.expensename):是什么类型的?
//方法写在后台
public string IsChecked(object obj)//obj的值为你绑定数据库的值
{
if(obj.tostring()="有")
{
return checked;
}
else if(obj.tostring()="无")
{
return checked;
}
else
{
return "";
}
}
#10
不是的,是页面加载时,将数据库字段isvoice[有/无]的值通过json绑定到那一组单选按钮中
如果数据库isvoice的值为"有",在修改页面加载后,radio就选中为"有",否则选中"无"
如果数据库isvoice的值为"有",在修改页面加载后,radio就选中为"有",否则选中"无"
#11
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>JavaScript</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
json = {'p_isvoice':'无'};
$("input[name='p_isvoice'][value=" + json.p_isvoice + "]").attr("checked","checked");
})
</script>
</head>
<body>
<input type="radio" name="p_isvoice" class="radio" value="有"/> 有
<input type="radio" name="p_isvoice" class="radio" value="无"/> 无
</body>
</html>
#12
// json是数据库的数据
$(function(){
$(":radio").each(function(){
if(json[this.id]){
this.value = "有";
}else{
this.value = "无";
}
});
});
#1
<input type="radio" name="p_isvoice" class="radio" value="有" /> 有
<input type="radio" name="p_isvoice" class="radio" value="无" checked/> 无
<input type="radio" name="p_isvoice" class="radio" value="无" checked/> 无
#2
<input type="radio" name="p_isvoice" class="radio" value="有" checked="checked"/> 有
<input type="radio" name="p_isvoice" class="radio" value="无"/> 无
<input type="radio" name="p_isvoice" class="radio" value="无"/> 无
#3
不是这样的,我要的是:这个按钮的值,它在数据库中为“有”的话,页面加载后,就选中为有;如果数据库中这个值是“无”的话,它就选中"无"
#4
首先你数据库中要有个存放是否选中的值吧,比如有个字段checked 1选中 0没选中
如果按照json格式取出 obj:{checked:1}
if(obj.checked==1){
$('p_isvoice').checked=checked;
}
如果按照json格式取出 obj:{checked:1}
if(obj.checked==1){
$('p_isvoice').checked=checked;
}
#5
<input type="text" id="expenseName" name="expenseName" style="width:200px" />
<input type="radio" name="p_isvoice" class="radio" value="有" /> 有
<input type="radio" name="p_isvoice" class="radio" value="无" checked/> 无
$(function(){
var el = $("#expenseName");
el.val("有");
$(":radio[name='p_isvoice']").each(function(){
var $this = $(this);
if (el.val() === $this.val()){
$this.attr("checked", "checked");
}
})
})
#6
$(":radio[name='p_isvoice'][value='"+$("#expenseName").val()+"']").attr("checked", "checked");
#7
<html>
<head>
<title>JavaScript</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("input[name='p_isvoice'][value='有']").attr("checked","checked")
})
</script>
</head>
<body>
<input type="radio" name="p_isvoice" class="radio" value="有"/> 有
<input type="radio" name="p_isvoice" class="radio" value="无"/> 无
</body>
</html>
#8
if(json.expensename!="")
{
$("#expenseName").get(0).checked = "checked ";
}
{
$("#expenseName").get(0).checked = "checked ";
}
#9
josn 我没绑过 ,不过如果你的意思用$("#expenseName").val(json.expensename)可以绑定数据库的值的话,你可以用下面的方法试试看:
<input type="radio" name="p_isvoice" class="radio" value="有" checked="
<%# IsChecked($("#expenseName").val(json.expensename))%> />
//$("#expenseName").val(json.expensename):是什么类型的?
//方法写在后台
public string IsChecked(object obj)//obj的值为你绑定数据库的值
{
if(obj.tostring()="有")
{
return checked;
}
else if(obj.tostring()="无")
{
return checked;
}
else
{
return "";
}
}
#10
不是的,是页面加载时,将数据库字段isvoice[有/无]的值通过json绑定到那一组单选按钮中
如果数据库isvoice的值为"有",在修改页面加载后,radio就选中为"有",否则选中"无"
如果数据库isvoice的值为"有",在修改页面加载后,radio就选中为"有",否则选中"无"
#11
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>JavaScript</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
json = {'p_isvoice':'无'};
$("input[name='p_isvoice'][value=" + json.p_isvoice + "]").attr("checked","checked");
})
</script>
</head>
<body>
<input type="radio" name="p_isvoice" class="radio" value="有"/> 有
<input type="radio" name="p_isvoice" class="radio" value="无"/> 无
</body>
</html>
#12
// json是数据库的数据
$(function(){
$(":radio").each(function(){
if(json[this.id]){
this.value = "有";
}else{
this.value = "无";
}
});
});