简体   繁体   中英

how can I set only one text from <a attribute list?

Here, I am trying to update input type a attribute text only, if the obj.idPartnerOffice == json.idPartnerOffice condition is true. How can I update project name only ?

  if (json.idPartnerProject == "0") { json.idPartnerProject = Math.random(); hidJson.Form5.Projects.push(json); $("#divbindProjectlist").append('<a href="#" id="anchorproject1" class="list-group-item projectList" >' + json.ProjectName + '<input type="hidden" name="hiddenproject1" class="hidprojectId" value="' + json.idPartnerProject + '" /></a>'); } else { $.each(hidJson.Form5.Projects, function (i, obj) { if (obj.idPartnerProject == json.idPartnerProject) { hidJson.Form5.Projects[i] = json; $("#anchorproject1").html(json.ProjectName).append('<input type="hidden" name="hiddenproject1" class="hidprojectId" value="' + json.idPartnerProject + '" />'); } }); } 

Here is image for html view with list of projects, 在此处输入图片说明

Now, All the hidden field values are changed. How can I fix it?

Your best bet is probably to move the hidden fields (which are missing name attributes btw) outside of the anchor tags (they're not clickable elements, anyway), add an id attribute to the anchors:

<a href="#" id="anchorproject1" class="list-group-item projectList">asdfasd</a>
<input type="hidden" name="hiddenproject1" class="hidprojectId" value="12345" />

and then use some jquery to access the text:

$("#anchorproject1").html("aaaaaa");

Edit:

You're in danger of having this question flagged for closure - you started off asking how to change the text in the anchor tag, and now you're asking about the hidden fields? Make up your mind - what do you actually need help with?

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