请指导,新手。
用mvc做一个录入及查询,后台传回josn没有问题,但是前台想依据后台的josn数据对dropdownlist进行设定值,尝试很多方法不可行。
前台代码:
function upData() {var phonevalue = document.getElementById("custom_phone").value;
if ($("#custom_phone").val() == "")
// if (phonevalue.replace(/\s/g, '') == '')
{ return; }
else
{
// 发送服务器请求
$.ajax({
datatype: "json",
type: "POST", //提交数据的类型 分为POST和GET 
async: true,
url: "/jp/phoneselect", //提交url 注意url必须小写 
data: { "phonevalue": phonevalue },
success: function (data) {
var jsondata = data;
con = "";
$.each(jsondata, function (index, item) {
$("#custom_xm").val(item.name);
if(item.sex=="男")
{
$("#sex-dropdownlist").selectedIndex ="1";
}
if (item.sex == "女")
{
$("#sex-dropdownlist").selectedvalue = "2";
}$("#custom_wx").val(item.wechat);
$("#custom_style").value=item.style;
$("#custom_capital").value = item.capital;
$("#custom_bz1").val(item.bz1);
$("#custom_bz1").val(item.bz2);
});
}
});
}
 
$("#custom_xm").val(item.name);有效,然后选择性别没有反应,dropdownlist上没有任何东西出现,请高手帮忙,非常感谢,非常感谢!