qq_35513892 2017-09-30 12:32 采纳率: 0%
浏览 4073

select标签"selected", true页面怎么不显示对应的option

$(function(){
$("#pcodeSelectId").on("change",function(){
var pcode = $("#pcodeSelectId").find("option:selected").val();
console.log("pcode--"+pcode);
$.ajax({
type: "get",
url: "http://127.0.0.1:8080/smw/item/getItemByPcode",
data: {pcode:pcode},
success: function(msg){
msg = eval(msg);
$("#pcodeSelectId option").each(function (index,doEle) {
if($(doEle).val() != msg.pcode){
$(this).attr("selected", false);
}else{
$(this).attr("selected", true);
}
});
$("#pnameSelectId option").each(function (index,doEle) {
if($(doEle).val() != msg.pname){
$(this).attr("selected", false);
}else{
$(this).attr("selected", true);
}
});
$("#pnameSelectId option[value='"+ msg.pname +"']").attr("selected",true );
$("#pcodeSelectId option[value='"+ msg.pcode +"']").attr("selected", true);
},
error:function(msg){
alert("请求失败");
}
});
});

$("#pnameSelectId").on("change",function(){
    var pname = $("#pnameSelectId").find("option:selected").val();
    console.log("pname--"+pname);
    $.ajax({
        type: "post",
        url: "http://127.0.0.1:8080/smw/item/getItemByPame",
        data: {pname:pname},
        success: function(msg){
            msg = eval(msg);
             $("#pcodeSelectId option").each(function (index,doEle) {
                    if($(doEle).val() != msg.pcode){
                        $(this).attr("selected", false);
                    }else{
                        $(this).attr("selected", true);
                    }
             });
             $("#pnameSelectId option").each(function (index,doEle) {
                    if($(doEle).val() != msg.pname){
                        $(this).attr("selected", false);
                    }else{
                        $(this).attr("selected", true);
                    }
             });
            $("#pnameSelectId option[value='"+ msg.pname +"']").attr("selected", true);
            $("#pcodeSelectId option[value='"+ msg.pcode +"']").attr("selected", true);
        },
        error:function(msg){
            alert("请求失败");
        }
    });

});

});

  • 写回答

1条回答 默认 最新

  • cuihu811371804 2017-10-03 15:37
    关注

    一次get一次post,不知道你放两次代码的意义,这个时候,起码要放相关html吧?ajax目前在被fetch逐渐取代,ajax中data,应该就看作一个字符串,
    所以一般会JSON.stringify(obj),后台代码也不知道,你这样描述问题,合适吗?

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog