0

我需要的是“这个”值

( $(this).attr("value")); 

出现在“这个”的

$("#activities_" +btn_id).val($(this).val());

这是代码。

$('.thoughts_list').click(function(){
    ( $(this).attr('id'));
    ( $(this).attr("value"));
}); 
    $('#close_thoughts').click(function(){

    $("#activities_" +btn_id).val($(this).val());   
}); 

目前,返回的值是“取消”,这是“#close_thoughts”的值,而不是我需要点击的“.thoughts列表”的值

回答,显然这就是我想要的。

$('.thoughts_list').click(function(){
    ( $(this).attr('id'));
    ( $(this).attr("value"));
}); 
    $('#close_thoughts').click(function(){

    $("#activities_" +btn_id).val($('input[name=thoughts_list]:checked').val());    
}); 
4

3 回答 3

0

If you want to get the value of the .thoughts_list element when you click the #close_thoughts element you'll need this:

$('#close_thoughts').click(function(){
    $("#activities_" + btn_id).val($('.thoughts_list').val());   
});

Your code was setup as follows:

$('#close_thoughts').click(function(){
    $("#activities_" +btn_id).val($(this).val());   
});

The problem here is that on the 2nd line $(this).val() is the same as $('#close_thoughts').val() and you're looking for $('.thoughts_list').val().

于 2013-01-23T22:29:23.613 回答
0

这也许?

$('.thoughts_list').on('click', function() {
    $("#activities_" + this.id).val(this.value);
});

你的问题很神秘。您是否尝试更改 ID 为activities_+ 单击元素 ID 的元素的值?如果是这样,上述将工作。如果没有,您需要进一步说明您的情况。

于 2013-01-23T22:29:50.220 回答
0

这是我的老板给我的工作。

$('.thoughts_list').click(function(){
    ( $(this).attr('id'));
    ( $(this).attr("value"));
}); 
    $('#close_thoughts').click(function(){

    $("#activities_" +btn_id).val($('input[name=thoughts_list]:checked').val());    
}); 
于 2013-01-24T21:34:16.960 回答