从jquery创建单选按钮
单选按钮工作不正常。在第一部分中,从控制器创建了一个下拉列表,在更改下拉项时,列表以$.json格式返回,我想将每个列表项显示为单选按钮标签。下面是我的代码从jquery创建单选按钮,jquery,asp.net-mvc,json,Jquery,Asp.net Mvc,Json,单选按钮工作不正常。在第一部分中,从控制器创建了一个下拉列表,在更改下拉项时,列表以$.json格式返回,我想将每个列表项显示为单选按钮标签。下面是我的代码 <div class="col9 last"> @Html.DropDownList("PaymentModelddl", new SelectList(listItems, "Value", "Text")) </div <div class="col9 right last" id="P
<div class="col9 last">
@Html.DropDownList("PaymentModelddl", new SelectList(listItems, "Value", "Text"))
</div
<div class="col9 right last" id="PlanNames">
</div>
<script>
$(document).ready(function () {
$('#PaymentModelddl').change(function () {
var ModelValue = $(this).val();
//alert(ModelValue+"");
if (ModelValue > 0) {
$.getJSON('/AccountInfoTemp/TestJSON/' + ModelValue, function (result) {
var ddl = $('#PlanNames');
ddl.empty();
var d = "";
$(result).each(function () {
d += "<input type='radio' name='radio' style='display:block; float:left;' />"
+ "<span class='label'>" + this.Name + "</span><div class='clear'></div>";
});
d += ""
ddl.html(d);
});
}
});
});
@DropDownList(“PaymentModelddl”,新选择列表(列表项,“值”,“文本”))
0) {
$.getJSON('/AccountInfoTemp/TestJSON/'+ModelValue,函数(结果){
var ddl=$(“#PlanNames”);
ddl.empty();
var d=“”;
$(结果)。每个(函数(){
d+=“”
+“+此。名称+”;
});
d+=“”
html(d);
});
}
});
});
尝试使用$。each()
:
$。每个(结果、函数(idx、项){
d+=“”
+“”+项目名称+“”;
});
$.each(result, function(idx, item) {
d += "<input type='radio' name='radio' style='display:block; float:left;' />"
+ "<span class='label'>" + item.Name + "</span><div class='clear'></div>";
});