简体   繁体   中英

how to get the appended value of input using jquery

I just want to ask to those master in jquery..

I have ajax

$.ajax({
    type: "POST",
    url: "URL",
    data: {
        DATA: DATA
    },
    beforeSend: function(){
        //action
    },
    success: function(result){
        $('.className').html(result);
    }
});

It already append the <input type="hidden" class="ClassName" value="1">

I try to use

$('.btnClick').on('click',function(){ $('.ClassName').val() }

but still it didn't get the appended input hidden value is there someone to help me?

Take care of the cases. className is not the same as ClassName . Also, an input does not have HTML inside, so calling html on it should not work, use val instead.

$('.className').html(result);

Should be

$('.ClassName').val(result);

Also, take care with the selectors. If you use the class name as a selector and you have multiple input fields with the same class name, the ajax bit will update all fields at once. Later, when you try to retrieve the value like you do, it will show only the value of the first one.

If you only plan on having one input with that class name, then you should probably use an id instead of a class, to avoid future confusions.

<input type="text" name="myname" id="myid" class="myclass" value="1">

Setting the value ...

$('#myid').val(result);

Getting the value ...

thevalue = $('#myid').val();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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