简体   繁体   English

jQuery在获得价值时奇怪的“未定义”反应

[英]jQuery strange “undefined” reaction while getting value

I have a problem with the variable. 我对变量有问题。 So i'm making post form with jQuery. 所以我正在用jQuery制作表单。 The input that i'm trying to get the info from is hidden: 我试图从中获取信息的输入被隐藏:

<input id="company_id" name="company_id" type="hidden" value="4">

And the jQuery code is like this: jQuery代码是这样的:

if (button == 'rem') {
    var term = $("#userlist").val();
    var comid = $( "#company_id").val();
    $.post('/delfromgroup', { id: term, cid: comid }, function(html){ 
        console.log(comid);
        $("#list").fadeOut("slow",function() { 
            $("#list").html($(html).filter("#error")); 
            $("#list").fadeIn("slow"); 
        });
    });
}

The first time, when i hit the button, its fine... the console.log says the right number, but after the first time, everytime when i press the button, the value is "undefined". 第一次,当我按下按钮时,它很好... console.log会显示正确的数字,但是第一次之后,每次当我按下按钮时,该值都是“ undefined”。 Why can't read the html code correctly after the first time? 为什么第一次后无法正确读取html代码? Any suggestions? 有什么建议么? Thank you :) 谢谢 :)

If your hidden field company_id would be inside #list then it will be removed by the jQuery code ( fadeOut() ) you have used. 如果您的隐藏字段company_id将在#list那么它将被您使用过的jQuery代码( fadeOut() )删除。

So when you call it next time, you are getting undefined. 因此,下次调用它时,您将变得不确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM