1

我无法让第二个 javascript 函数工作。当我单击“发送邮件”按钮时,它应该调用第二个函数并将这两个值传递给它。href 行(第一个函数中的倒数第二行)未正确呈现。

<script>
function getvals(first,second) {
    alert(''+first+'');
    alert(''+second+'');
    mywindow=window.open('','Send Mail','height=200,width=400');
    mywindow.document.write("<FORM NAME='test'>");
    mywindow.document.write("<table align='center'><tr><td>User/Group: </td><td><input type='text' id='newfirst' name='iuser'></td></tr>");
    mywindow.document.test.iuser.value = ''+first+'';
    mywindow.document.write("<tr><td>Issue Key: </td><td><input type='text' id='newsecond' name='ikey'></td></tr>");
    mywindow.document.test.ikey.value = ''+second+'';
    mywindow.document.write("<tr><td><a href='javascript:popitup(document.getElementById('newuser').value,document.getElementById('newkey').value);'>Send Mail</a></td></tr></table>");
    mywindow.document.write("</FORM>");
}
function popitup(user,key) {
    alert(''+user+'');
    alert(''+key+'');
    var url = 'http:\/\/localhost:8080/plugins/servlet/mailservlet?receiver=' + user + '&issue=' + key;
    newwindow=window.open(url,'name','height=400,width=400');
    if (window.focus) {newwindow.focus()}
}
</script>
4

4 回答 4

3

该函数popitup不会被调用,因为它是写在父窗口中的,而不是在打开的窗口中window.open。试试window.opener你的函数调用。

于 2012-12-17T09:44:27.173 回答
1

嵌套引号问题,您应该正确地逃避它:

 mywindow.document.write("<tr><td><a href='javascript:popitup(document.getElementById(\"newuser\").value,document.getElementById(\"newkey\").value);'>Send Mail</a></td></tr></table>");
于 2012-12-17T09:44:37.533 回答
0

看到它工作

  function getvals(first,second) {
      alert(''+first+'');
      alert(''+second+'');
      mywindow=window.open('','Send Mail','height=200,width=400');
      mywindow.document.write("<FORM NAME='test'>");
      mywindow.document.write("<table align='center'><tr><td>User/Group: </td><td><input type='text' id='newfirst' name='iuser'></td></tr>");
      mywindow.document.test.iuser.value = ''+first+'';
      mywindow.document.write("<tr><td>Issue Key: </td><td><input type='text' id='newsecond' name='ikey'></td></tr>");
      mywindow.document.test.ikey.value = ''+second+'';
      mywindow.document.write("<tr><td><a href=\"javascript:opener.popitup(document.getElementById('newfirst').value,document.getElementById('newsecond').value);\">Send Mail</a></td></tr></table>");
      mywindow.document.write("</FORM>");
  }

  function popitup(user,key) {
      alert(''+user+'');
      alert(''+key+'');
      var url = 'http:\/\/localhost:8080/plugins/servlet/mailservlet?receiver=' + user + '&issue=' + key;
      newwindow=window.open(url,'name','height=400,width=400');
      if (window.focus) {newwindow.focus()}
  }

已修复的问题:
1) window.open 中的转义问题
2) 函数调用应该是 opener.popitup
3) 用户和密钥的 ID 名称不正确。

于 2012-12-17T09:58:40.780 回答
0

请不要这样做(文件写)

使用 appendChild,并在此处附加 onclick-handler

于 2012-12-17T09:59:44.303 回答