要求根据视图中变更项目(CICD)决定变更值(CHV)是text还是dropdownlist
<tr>
<th style="width:20%"><font class="redstar">*</font>变更项目</th>
<td>
@Html.DropDownListFor(model => model.CICD, new SelectList(Dics.GetItems(Dics.DicTypes.itmJczBgxm, true), "CD", "NM", "20"),new { onchange = "MinDate()" })
@Html.ValidationMessageFor(model => model.CICD)
</td>
</tr>
<tr>
<tr>
<th>变更值</th>
<td>
@Html.TextBoxFor(model => model.CHV, new { htmlAttributes = new { } })
@Html.ValidationMessageFor(model => model.CHV)
</td>
</tr>
我的思路是:绑定onblur()方法,使用ajax提交到后台,从后台进行判断。
视图中js语句:
function ChoseInputStyle() {
var a = $('#CICD').val();
$.ajax({
type: "post",
//dataType:"json",
url: '/StchAtt/InputStyle ',
data: {cicd: a },
success: function (data) {
if (data == "jczlb") {
$('#CHV').
//这里不会写
}
});
}
控制器中方法:
public string InputStyle(string cicd)
{
string input = "";
if (cicd != null)
{
if(cicd=="01" || cicd == "02" || cicd == "05" || cicd == "06" || cicd == "07")
{
input = "text";
return input;
}
else if (cicd == "08")
{
//jczlb--"监测站类别"首字母
input = "jczlb";
return input;
}
}
return input;
}
希望各位大神们bang'bang'mang
if(data.value=='你进行判断的字段'){
$("#result").parent().empty();//获取对象父级元素清空
var innerHtml = "你要写的下拉框";
$('#你所在的div').append(innerHtml)
}else{
$("#result").parent().empty();//获取对象父级元素清空
var innerHtml ="<input type=\"text\" id=\"result\" style=\"width:180px;\" maxlength=\"18\" />";
$('#resultdiv').append(innerHtml)
};
这个判断不需要后台逻辑为什么要提交后台处理,直接JS处理就可以了啊