JavaScript 打开窗口

发布于 2024-11-04 20:13:50 字数 2687 浏览 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+" <input type='text' name='ref_docs' value='"+name+"'></input><input type='text'  name='ref_nos' value='"+number+"'></input></li>";
    opener.jQuery("#r_docs").append(jQuery(html));
}

调用上述函数的函数是:

function addRefDoc(){

    var count = 0;
    var ref_docarray ;
    var ref_noarray ;

    <%for(int i1=0; i1<vec.size(); i1++) {
        prop = (Properties) vec.get(i1);
        String ref_no = prop.getProperty("referral_no","");
        String ref_name = (prop.getProperty("last_name", "")+ ","+ prop.getProperty("first_name", ""));
    %>
    if(document.getElementById("refcheckbox_<%=ref_no%>").checked) {
        count++;

        if ((ref_doctor!=null)&&(ref_doctor!="")&&(ref_docno!=null)&&(ref_docno!="")) {
            ref_docarray = ref_doctor.split(";");
            ref_noarray = ref_docno.split(";");

            if ((containsElem(ref_docarray,"<%=ref_name%>"))||(containsElem(ref_noarray,<%=ref_no%>))) {
                alert("Referral doctor " + "<%=ref_name%>" + " already exists");
            } else {
                AddOtherRefDoc("<%=ref_name%>", <%=ref_no%>);
            }
        } else {
            AddOtherRefDoc("<%=ref_name%>", <%=ref_no%>);
        }
    } 

    <%} %>

    self.close();
}

function containsElem(array1,elem) {
    for (var i=0;i<array1.length;i++) {
        if(array1[i]==elem){
        return true;
        } else{
            return false;
        }
    }
}

调用此函数时,它应该将 2 个输入元素“ref_docs”和“ref_nos”携带到打开此窗口的页面中。但它并没有这样做。它列出了正确的元素,但是当我尝试在第一个窗口的另一个 Javascript 函数中使用“ref_docs”和“ref_nos”时,我看到“ref_nos”和“ref_docs”是空的。

我做错了什么?

function updateRd(){ 
   var ref_docs = jQuery("#updatedelete").find('input[name="ref_docs"]'); 
   var ref_nos = jQuery("#updatedelete").find('input[name="ref_nos"]');                       alert(ref_docs.val() + ref_nos.val()); 
  var rdocs = new Array(); 
  var rnos = new Array(); 
  ref_docs.each(function() { rdocs.push($(this).val()); } ); 
  ref_nos.each(function() { rnos.push($(this).val()); } );                               
  $('#r_doctor').val(rdocs.join(";")); 
$('#r_doctor_ohip').val(rnos.join(";")); }

– 此函数返回一个错误,指出“ref_docs”和“ref_nos”未定义。

I have function that opens up a window, and the values from the newly opened window are listed in the opener window.
The 2nd window - has this function:

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+" <input type='text' name='ref_docs' value='"+name+"'></input><input type='text'  name='ref_nos' value='"+number+"'></input></li>";
    opener.jQuery("#r_docs").append(jQuery(html));
}

The function that calls the one above is:

function addRefDoc(){

    var count = 0;
    var ref_docarray ;
    var ref_noarray ;

    <%for(int i1=0; i1<vec.size(); i1++) {
        prop = (Properties) vec.get(i1);
        String ref_no = prop.getProperty("referral_no","");
        String ref_name = (prop.getProperty("last_name", "")+ ","+ prop.getProperty("first_name", ""));
    %>
    if(document.getElementById("refcheckbox_<%=ref_no%>").checked) {
        count++;

        if ((ref_doctor!=null)&&(ref_doctor!="")&&(ref_docno!=null)&&(ref_docno!="")) {
            ref_docarray = ref_doctor.split(";");
            ref_noarray = ref_docno.split(";");

            if ((containsElem(ref_docarray,"<%=ref_name%>"))||(containsElem(ref_noarray,<%=ref_no%>))) {
                alert("Referral doctor " + "<%=ref_name%>" + " already exists");
            } else {
                AddOtherRefDoc("<%=ref_name%>", <%=ref_no%>);
            }
        } else {
            AddOtherRefDoc("<%=ref_name%>", <%=ref_no%>);
        }
    } 

    <%} %>

    self.close();
}

function containsElem(array1,elem) {
    for (var i=0;i<array1.length;i++) {
        if(array1[i]==elem){
        return true;
        } else{
            return false;
        }
    }
}

When this function is called, it is supposed to carry the 2 input elements "ref_docs" and "ref_nos" into the page that opened this window. But it is not doing so. It lists the elements alright but when I try to use "ref_docs" and "ref_nos" in another Javascript function in the 1st window, I see that "ref_nos" and "ref_docs" are empty.

What am I doing wrong?

function updateRd(){ 
   var ref_docs = jQuery("#updatedelete").find('input[name="ref_docs"]'); 
   var ref_nos = jQuery("#updatedelete").find('input[name="ref_nos"]');                       alert(ref_docs.val() + ref_nos.val()); 
  var rdocs = new Array(); 
  var rnos = new Array(); 
  ref_docs.each(function() { rdocs.push($(this).val()); } ); 
  ref_nos.each(function() { rnos.push($(this).val()); } );                               
  $('#r_doctor').val(rdocs.join(";")); 
$('#r_doctor_ohip').val(rnos.join(";")); }


This function returns an error saying "ref_docs" and "ref_nos" are undefined.

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

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

发布评论

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

评论(2

羁〃客ぐ 2024-11-11 20:13:50

我认为它正在尝试使用其他页面上的 jQuery 来查找当前页面上的“#r_docs”。

尝试:

jQuery(opener.document).find("#r_docs").append(html);

UPDATE:

我在您的更新函数document.updatedelete中创建了index.html:

<!DOCTYPE html>
<html><head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title> - jsFiddle demo</title>
  <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.js"></script>
  <script type="text/javascript">
  window.jQuery = jQuery;
  function openChild ()
  {
      var mychildwin = window.open("child.html");
  }
  </script>
  </head>
<body>

<input type="button" value="click" onclick="openChild();" />

<div id="r_docs">
Redocs here.
</div>
</body>
</html>

和child.html:

<!DOCTYPE html>
<html><head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title> - jsFiddle demo</title>
  <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.js"></script>
  <script type="text/javascript">
  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+" <input type='text' name='ref_docs' value='"+name+"'></input><input type='text'  name='ref_nos' value='"+number+"'></input></li>";
        jQuery(opener.document).find("#r_docs").append(html);
    }
  </script>
  </head>
<body>

<input type="button" value="click" onclick="AddOtherRefDoc('name', 42);"/>

</body>
</html>

UPDATE2:

没有属性ref_docs并且参考号。

尝试:

jQuery("#updatedelete")
    .find('input[name="ref_docs"], input[name="ref_nos"]')

你的表格在哪里

<form id="updatedelete" ... >

I think it is trying to use the jQuery on the other page to find "#r_docs" on the current page.

Try:

jQuery(opener.document).find("#r_docs").append(html);

UPDATE:

I created index.html:

<!DOCTYPE html>
<html><head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title> - jsFiddle demo</title>
  <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.js"></script>
  <script type="text/javascript">
  window.jQuery = jQuery;
  function openChild ()
  {
      var mychildwin = window.open("child.html");
  }
  </script>
  </head>
<body>

<input type="button" value="click" onclick="openChild();" />

<div id="r_docs">
Redocs here.
</div>
</body>
</html>

and child.html:

<!DOCTYPE html>
<html><head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title> - jsFiddle demo</title>
  <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.js"></script>
  <script type="text/javascript">
  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+" <input type='text' name='ref_docs' value='"+name+"'></input><input type='text'  name='ref_nos' value='"+number+"'></input></li>";
        jQuery(opener.document).find("#r_docs").append(html);
    }
  </script>
  </head>
<body>

<input type="button" value="click" onclick="AddOtherRefDoc('name', 42);"/>

</body>
</html>

UPDATE2:

in your update function document.updatedelete has no attributes ref_docs and ref_nos.

try:

jQuery("#updatedelete")
    .find('input[name="ref_docs"], input[name="ref_nos"]')

Where your form is

<form id="updatedelete" ... >
欢烬 2024-11-11 20:13:50

您访问 DOM 元素的函数不正确。 updatedelete 不是 document 的属性,访问 ref_docsref_nos 属性也不会自动构建的集合代码>输入元素。既然您已经在使用 jQuery,请尝试以下操作:

var ref_docs = $('input[name="ref_docs"]');
var ref_nos = $('input[name="ref_nos"]');

这将为您提供数组(或至少类似数组)对象,让您访问输入:

var rdocs = new Array();
var rnos = new Array();

ref_docs.each(function() { rdocs.push($(this).val()); } );
ref_nos.each(function() { rnos.push($(this).val()); } );

$('#r_doctor').val(rdocs.join(";"));
$('#r_doctor_ohip').val(rnos.join(";"));

Your function that accesses the DOM elements is incorrect. updatedelete is not a property of document, nor will accessing a ref_docs or ref_nos property automatically build a collection of input elements. Since you're using jQuery already, try this:

var ref_docs = $('input[name="ref_docs"]');
var ref_nos = $('input[name="ref_nos"]');

That will give you Array (or at least array-like) objects that will let you access your inputs:

var rdocs = new Array();
var rnos = new Array();

ref_docs.each(function() { rdocs.push($(this).val()); } );
ref_nos.each(function() { rnos.push($(this).val()); } );

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