简体   繁体   English

我怎样才能只设置一个文本

[英]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. 在这里,如果obj.idPartnerOffice == json.idPartnerOffice条件为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, 这是带有项目列表的html视图的图像, 在此处输入图片说明

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: 最好的选择是将隐藏字段(缺少名称属性btw)移到锚标签(无论如何它们都不是可点击元素)之外,向锚添加id属性:

<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: 然后使用一些jQuery来访问文本:

$("#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? 下定决心-您实际上需要什么帮助?

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

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