将无序列表从弹出窗口填充到主窗口中 - javascript
在我的父窗口中,我有一个列表:
<span id="r_doc_span">
<ul id="r_docs">
<li>
<input id="r_doctor" type="hidden" name="r_doctor" size="40" value="<%=rd%>">
<input id="r_doctor_ohip" type="hidden" name="r_doctor_ohip" size="20" value=<%=rdohip%>>
</li>
</ul></tr>
我想从弹出窗口填充此列表。我有 2 个 javascript 函数用于此目的:
function addRefDoc(){
<% prop = (Properties) vec.get(i1);
String ref_no = prop.getProperty("referral_no","");
String ref_name = (prop.getProperty("last_name", "")+ ","+prop.getProperty("first_name", "")); %>
AddOtherRefDoc("<%=ref_name%>", <%=ref_no%>);
}
function AddOtherRefDoc(name, number) {
var remove = "<a href='javascript:void(0) onclick='removeRefDoctor(this)'>remove</a>";
var html = "<li>"+name+"<b>, Referral No: </b>"+number+ " " +remove+"</li>";
jQuery("#r_docs").append(jQuery(html));
}
但是此代码没有任何反应。我如何填充我的列表?请帮忙。
In my parent window, I have a list :
<span id="r_doc_span">
<ul id="r_docs">
<li>
<input id="r_doctor" type="hidden" name="r_doctor" size="40" value="<%=rd%>">
<input id="r_doctor_ohip" type="hidden" name="r_doctor_ohip" size="20" value=<%=rdohip%>>
</li>
</ul></tr>
I want to populate this list from a pop-up window. I have 2 javascript functions for this purpose:
function addRefDoc(){
<% prop = (Properties) vec.get(i1);
String ref_no = prop.getProperty("referral_no","");
String ref_name = (prop.getProperty("last_name", "")+ ","+prop.getProperty("first_name", "")); %>
AddOtherRefDoc("<%=ref_name%>", <%=ref_no%>);
}
function AddOtherRefDoc(name, number) {
var remove = "<a href='javascript:void(0) onclick='removeRefDoctor(this)'>remove</a>";
var html = "<li>"+name+"<b>, Referral No: </b>"+number+ " " +remove+"</li>";
jQuery("#r_docs").append(jQuery(html));
}
But nothing happens with this code. How can I populate my list? Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 Matt Ball 所说,至少弹出窗口引用的函数之一不是 JavaScript,看起来更像 C#。现在经过编辑,<%
/ < code>%> 在那里。从弹出窗口中,您可以访问父窗口上带有
id
的元素,如下所示:通过 jQuery 对象获取对父窗口上的
r_doctor
元素的引用那个窗户。 (子窗口通过window.opener
属性获取对其父窗口的引用。)这是一个实例< /a>,代码的核心内容(例如上面的行)在弹出窗口中。在那里,我使用了
文本
而不是隐藏
输入,但这只是为了让您可以看到发生了什么。As Matt Ball said, at least one of your quoted functions for the popup isn't JavaScript, looks more like C#.Now with the edit, the<%
/%>
are there.From a popup window, you can access elements with
id
s on the parent window like this:That gets a reference to the
r_doctor
element on the parent window via the jQuery object in that window. (Child windows get a reference to their parent via thewindow.opener
property.)Here's a live example, the meat of the code (e.g., the line above) being here in the popup. There I've used a
text
rather thanhidden
input, but that's just so you can see what's going on.