[英]Need help selecting an element from a jquery response
I am trying to get the value of a hidden input element from a jquery ajax response. 我试图从jquery ajax响应中获取隐藏的输入元素的值。 The default value for the hidden element is 0. But after the jquery post has been completed the hidden input value attribute gets changed to a different number(by php) hidden元素的默认值为0。但是在jquery帖子完成后,hidden input value属性将更改为另一个数字(通过php)
For some reason when I select the element from the data var (the response variable) and pass it into the html() function, it shows the value as 0 for the hidden input 由于某种原因,当我从数据变量(响应变量)中选择元素并将其传递给html()函数时,对于隐藏的输入,该值显示为0
Below is my code... 下面是我的代码...
$.post(url,obj_param)
.done(function (data) {
console.log(data);
var thread_id = $("#thread").html(data);
console.log(thread_id);
});
}
Here is a snippet of my html code 这是我的html代码的一小段
<section class="message_form">
<form action="http://localhost/GuruCoders/index.php/messages/NewMessageThread/index" class='msg_form' id='59' method="post" accept-charset="utf-8">
<div id="err_msg"> Please enter a message to send </div>
<textarea name="msg" class="msg" id="59" cols="30" rows="10"></textarea>
<br>
<input type="submit" name="send" value="Send">
</form>
<!-- The value returns as 0 not 55 -->
<input type="hidden" id="thread" value="55" name="thread"/>
</section>
Well first of all I don't know why you use $("#thread").html(data);
首先,我不知道为什么要使用$("#thread").html(data);
.. ..
However, if you want to SET the value you can use $("#thread").val(data);
但是,如果要设置该值,则可以使用$("#thread").val(data);
and if you want to GET the value you can use $("#thread").val();
如果要获取值,可以使用$("#thread").val();
. 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.