简体   繁体   中英

how to get input new attribute value

I try set new value for input 'pid' attribute and get this, but I get null .

I have this code in jquery:

$(".feauter-product-holder").click(function () {
  $("#productsubject").attr("pid", $(this).find("input[type=hidden]").attr("id"));
});

and my code in HTML:

<div class='feauter-product-holder'>
  <input type="hidden" id="3">
</div>
<asp:TextBox runat="server" ID="productsubject" pid=""></asp:TextBox></div>
 $.ajax({
                    url: editor.config.saveSubmitURL,//the url to post at... configured in config.js
                    type: 'POST',
                    data: { servicename: "savedata", text: data, subject: $("#productsubject").val(), pid: $("input[id$='productsubject").attr("pid") },//editor.name contains the id of the current editable html tag
                })

i edit this post i write wrong class div,but in my code is correct. when i call pid in ajax i get null

What should I do?

Your DIV can't be found because of a wrong css class call. Try:

<div class="feauter-product-holder">

First of all remove "." from class name in DIV and then you can try like this :-

$(".feauter-product-holder").click(function () {
  $("input[id$='productsubject']").attr("pid", $(this).find("input[type=hidden]").attr("id"));
});

While Handling with ASP control with Jquery you use like (Element ends with selector) example :- $("input[id$='productsubject']") .. $("#productsubject") won't work .

Actually in ASP.NET if you use asp control with some ID, ASP.NET Naming container changes the control ID like ctl001_yourcontrolID to avoid conflicts. Hence, in Jquery when you select a element by simply its ID(like $("#productsubject") ) , you will not get that element since its ID has been changed. to illustrate, you can inspect the asp control in Firebug or chrome's inspect element.

Hence when you write $("input[id$='productsubject']") ,it select the element whose ID ends with productsubject .

You have 2 problems - the class on the div is incorrect, and also .net will change the id of the text box.

Try

<div class="feauter-product-holder"> 

for the div.

If you are using .net 4 you can set ClientIDMode="Static" on the text box like this

<asp:TextBox runat="server" ID="productsubject" pid="" ClientIDMode="Static"></asp:TextBox></div>

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