簡體   English   中英

無法獲得第二個javascript函數嗎?

[英]can't get the second javascript function to work?

我無法獲得第二個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>

函數popitup將不會被調用,因為它是在父窗口中寫入的,而不是在window.open打開的窗口中。 在函數調用中嘗試window.opener

嵌套引號問題,你可以正確地逃避它:

 mywindow.document.write("<tr><td><a href='javascript:popitup(document.getElementById(\"newuser\").value,document.getElementById(\"newkey\").value);'>Send Mail</a></td></tr></table>");

看它工作

  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名稱不正確。

請不要這樣做(文件寫)

使用appendChild,並在那里附加onclick-handler

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM