假设我有一个像下面这样的函数
<code>
<pre>
function messageHandler(user_id,add_remove_id)
{
var type=3;
var data = 'user_id=' + user_id+'&add_remove_id='+add_remove_id+'&type='+type;
alert(data);
$.ajax({
type:"POST",
url:"add_rem_friend.php",
data:data,
success:function(html) {
//**********************************************
// i want to put the value of add_remove_id, which i taking as argument/parameter
// $('#add_remove_id').html(html); will not work
// is there any way?
//*************************************************
}
});
return false;
}
</pre>
</code>
我想输入 add_remove_id 的值,我将其作为参数/参数
<pre>
$('#add_remove_id').html(html); will not work
</pre>
有什么办法吗?
最佳答案
问题是:add_remove_id 是一个字符串变量,您必须将此字符串连接到 jquery 选择器。
试试这个:
$('#'+add_remove_id).html(html);
如果您使用:
$('#add_remove_id').html(html);
jQuery 搜索 id = add_remove_id 的元素
关于javascript - 如何在jquery中动态打印id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17389087/