Jquery get .val

后端 未结 3 721
暗喜
暗喜 2021-01-26 13:22

What I need is the \"this\" value of

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

to show up in the \"this\" of

$(\"#activities_\" +btn_id).val         


        
相关标签:
3条回答
  • 2021-01-26 14:02

    This is what my boss gave me to work with.

    $('.thoughts_list').click(function(){
        ( $(this).attr('id'));
        ( $(this).attr("value"));
    }); 
        $('#close_thoughts').click(function(){
    
        $("#activities_" +btn_id).val($('input[name=thoughts_list]:checked').val());    
    }); 
    
    0 讨论(0)
  • 2021-01-26 14:05

    This perhaps?

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

    Your question is quite cryptic. Are you trying to change the value for the element with an ID of activities_ + the ID of the clicking element? If so, the above will work. If not, you need to elucidate your situation a bit more.

    0 讨论(0)
  • 2021-01-26 14:09

    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().

    0 讨论(0)
提交回复
热议问题