简体   繁体   English

如何使用jquery获取输入的附加值

[英]how to get the appended value of input using jquery

I just want to ask to those master in jquery..我只想问问那些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">它已经附加了<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 . classNameClassName Also, an input does not have HTML inside, so calling html on it should not work, use val instead.此外, input内部没有 HTML,因此在其上调用html不应该起作用,请改用val

$('.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.如果您使用类名作为选择器,并且您有多个具有相同类名的输入字段,则 ajax 位将一次更新所有字段。 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.如果您只计划使用该类名输入一个,那么您可能应该使用 id 而不是类,以避免将来混淆。

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

Setting the value ...设置值...

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

Getting the value ...获取价值...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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