动态更新输入字段 javascript jquery

发布于 2024-11-03 10:47:30 字数 1397 浏览 1 评论 0原文

我的添加和删除函数如下:

function AddOtherRefDoc(name, number) {
  var remove = "<a href='javascript:void(0);' onclick='removeRefDoctor(this)'>Remove</a>";
  var html = "<li><b> Referral Doctor: </b>"+name+"<b>, Referral No: </b>"+number+ " " +remove+"</li>";
opener.jQuery("#r_docs").append(jQuery(html));
}

function removeRefDoctor(el) { 
var el = jQuery(el);
if (el) { el.parent().remove(); }
else { alert("Unable to remove recipient."); }  

}

removeRefDoctor 函数删除当前元素,但我的输入字段不会更新。如何更新以下输入字段?

<ul id="r_docs" >

<% StringTokenizer rdlist = new StringTokenizer(rd,";");
   StringTokenizer rdnolist = new StringTokenizer(rdohip,";");
   while (rdlist.hasMoreTokens() && rdnolist.hasMoreTokens()) {
     String rd_split = rdlist.nextToken();
     String rdno_split = rdnolist.nextToken();  %>      
<li>Referral Doctor: <%=rd_split%><b>, Referral No: </b><%=rdno_split%> <a href='javascript:void(0);' onclick='removeRefDoctor(this)'>Remove</a></li>
<%} %>  
<input id="r_doctor" type="hidden" name="r_doctor" size="150" value="<%=rd%>">
<input id="r_doctor_ohip" type="hidden" name="r_doctor_ohip"
                                            size="60" value="<%=rdohip%>">

</ul>

I have my add and remove functions as follows:

function AddOtherRefDoc(name, number) {
  var remove = "<a href='javascript:void(0);' onclick='removeRefDoctor(this)'>Remove</a>";
  var html = "<li><b> Referral Doctor: </b>"+name+"<b>, Referral No: </b>"+number+ " " +remove+"</li>";
opener.jQuery("#r_docs").append(jQuery(html));
}

function removeRefDoctor(el) { 
var el = jQuery(el);
if (el) { el.parent().remove(); }
else { alert("Unable to remove recipient."); }  

}

The removeRefDoctor function removes the current element but my input field doesn't get updated. How can I update the following input fields?

<ul id="r_docs" >

<% StringTokenizer rdlist = new StringTokenizer(rd,";");
   StringTokenizer rdnolist = new StringTokenizer(rdohip,";");
   while (rdlist.hasMoreTokens() && rdnolist.hasMoreTokens()) {
     String rd_split = rdlist.nextToken();
     String rdno_split = rdnolist.nextToken();  %>      
<li>Referral Doctor: <%=rd_split%><b>, Referral No: </b><%=rdno_split%> <a href='javascript:void(0);' onclick='removeRefDoctor(this)'>Remove</a></li>
<%} %>  
<input id="r_doctor" type="hidden" name="r_doctor" size="150" value="<%=rd%>">
<input id="r_doctor_ohip" type="hidden" name="r_doctor_ohip"
                                            size="60" value="<%=rdohip%>">

</ul>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北座城市 2024-11-10 10:47:30
function removeRefDoctor(el) { 
var el = jQuery(el);
if (el) { 
el.parent().remove(); 
$('#r_doctor').val('');
$('#r_doctor_ohip').val('');
}
else { alert("Unable to remove recipient."); }
function removeRefDoctor(el) { 
var el = jQuery(el);
if (el) { 
el.parent().remove(); 
$('#r_doctor').val('');
$('#r_doctor_ohip').val('');
}
else { alert("Unable to remove recipient."); }
半世蒼涼 2024-11-10 10:47:30

你的问题有点令人困惑...但无论如何...将值插入隐藏字段...

html

<input id="testInput" type="hidden" />

js

var dataStr = "element1;element2;element3;element4";
$('#testInput').text(dataStr);

your question is a little bit confusing... but here goes anyways... to insert a value into a hidden field...

html

<input id="testInput" type="hidden" />

js

var dataStr = "element1;element2;element3;element4";
$('#testInput').text(dataStr);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文