function writeBody(str)
{
...
wPopupDoc.write('<body bgcolor="buttonface" leftmargin="0" topmargin="0" onload="alert()">');
...
}
想让alert()带str,请问如何传递?

解决方案 »

  1.   

    wPopupDoc.write(' <body bgcolor="buttonface" leftmargin="0" topmargin="0" onload="alert()">'); 就是想让alert()带参数,比如是alert(str)或alert("This is a sample.")单独这样是可以的,但是一旦放到write()函数中就有问题了。
      

  2.   

    wPopupDoc.write(' <body bgcolor="buttonface" leftmargin="0" topmargin="0" onload="alert('+str+')">'); 
      

  3.   

    wPopupDoc.write(' <body bgcolor="buttonface" leftmargin="0" topmargin="0" onload="alert(\''+str+'\')">'); 
      

  4.   

    str是变量不是字符串形式的吧
      

  5.   

    alert()直接留空这样,还能弹出对话框。
    alert('+str+')到时不报错,但不能弹出对话框。保存到一个Html 文件中,点按钮,应该就会弹出对话框的。<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body>
    <script>
    <!--
    var iFlag=4;
    function search() {
    var str="a";
    var wPopupElements=wPopup.document.all;
    if (wPopupElements.textcase.checked)
      {iFlag=4;}
    else
      {iFlag=0;}
    if (wPopupElements.searchtext.value==null || wPopupElements.searchtext.value=='')
      {
       wPopup.alert("Specify a value to search for");
       return;
      }
    if (rng.findText(str,10000,iFlag)==true)//wPopupElements.searchtext.value
      {
       rng.select();
       rng.scrollIntoView();
       rng.moveStart("character");
      }
    else 
      {wPopup.alert("End of document");}
    }function replace() {
    var wPopupElements=wPopup.document.all;
    if (wPopupElements.textcase.checked)
      {iFlag=4;}
    else
      {iFlag=0;}
    if (wPopupElements.searchtext.value==null || wPopupElements.searchtext.value=='')
      {
       wPopup.alert("Specify a value to replace for");
       return;
      }
    if (rng.findText(wPopupElements.searchtext.value,-10000,iFlag)==true)
      {
       rng.text = wPopupElements.replacetext.value;
      }
    else 
      {wPopup.alert("End of document");}
    }function replaceall() {
    var rng = document.body.createTextRange();
    var wPopupElements=wPopup.document.all;
    if (wPopupElements.textcase.checked)
      {iFlag=4;}
    else
      {iFlag=0;}
    if (wPopupElements.searchtext.value==null || wPopupElements.searchtext.value=='')
      {
       wPopup.alert("Specify a value to replace for");
       return;
      }
      for (i=0; rng.findText(wPopupElements.searchtext.value,10000,iFlag)!=false; i++)
      {
       rng.scrollIntoView();
       rng.text = wPopupElements.replacetext.value;
      }
      setTimeout('wPopup.alert(i + " item(s) replaced!")',200);
    }
    //-->
    </script><script>
    <!--
    function gofind(str) {
    wPopup=window.open('about:blank','','width=350 height=110 left=200 top=200 menubar=no resizeable=no scrollbars=no toolbar=no');
    var wPopupDoc=wPopup.document;
    wPopupDoc.open();
    wPopupDoc.write('<html>');
    wPopupDoc.write('<head>');
    wPopupDoc.write('<title>Find and Replace-www.51windows.Net</title>');
    wPopupDoc.write('<style>');
    wPopupDoc.write('body,td,div,{font:menu}');
    wPopupDoc.write('button {width:80}');
    wPopupDoc.write('</style>');
    wPopupDoc.write('</head>');
    wPopupDoc.write(' <body bgcolor="buttonface" leftmargin="0" topmargin="0" onload="alert()">'); 
    wPopupDoc.write('<table width="350" border="0" cellspacing="0" cellpadding="3" bgcolor="buttonface">');
    wPopupDoc.write('<tr>');
    wPopupDoc.write('<td>Find what:</td>');
    wPopupDoc.write('<td><input type="text" name="searchtext" onchange="window.opener.rng=window.opener.document.body.createTextRange()"></td>');
    wPopupDoc.write('<td><button accesskey="S" name="searchbutton" onclick="window.opener.search()"><u>S</u>earch</button></td>');
    wPopupDoc.write('</tr>');
    wPopupDoc.write('<tr>');
    wPopupDoc.write('<td>Replace with:</td>');
    wPopupDoc.write('<td><input type="text" name="replacetext"></td>');
    wPopupDoc.write('<td><button accesskey="R" name="replacebutton" onclick="window.opener.replace()"><u>R</u>eplace</button></td>');
    wPopupDoc.write('</tr>');
    wPopupDoc.write('<tr>');
    wPopupDoc.write('<td colspan="2"><input type="checkbox" name="textcase" value="textcase">Match Case</td>');
    wPopupDoc.write('<td><button accesskey="A" name="replaceallbutton" onclick="window.opener.replaceall()">Replace<u>A</u>ll</button></td>');
    wPopupDoc.write('</tr>');
    wPopupDoc.write('<tr>');
    wPopupDoc.write('<td colspan="2">&nbsp;</td>');
    wPopupDoc.write('<td><button accesskey="C" name="cancelbutton" onclick="window.close()"><u>C</u>ancel</button></td>');
    wPopupDoc.write('</tr>');
    wPopupDoc.write('</table>');
    wPopupDoc.write('</body>');
    wPopupDoc.write('</html>');
    wPopupDoc.close();
    }
    //-->
    </script>
    <button onclick="gofind('Flash')">Find and Replace</button><pre style="font:menu">
    What is FlashGet? 
    --------------------------------------------------------------------------------FlashGet is specifically designed to address two of the biggest problems when downloading files: Speed and management of downloaded files.If you've ever waited forever for your files to download from a slow connection, or been cut off midway through a download - or just can't keep track of your ever-growing downloads - FlashGet is for you. FlashGet can split downloaded files into sections, downloading each section simultaneously, for an increase in downloading speed from 100% to 500%. This, coupled with FlashGet's powerful and easy-to-use management features, helps you take control of your downloads like never before.--------------------------------------------------------------------------------Speed
    FlashGet can automatically split files into sections or splits, and download each split simultaneously. Multiple connections are opened to each file, and the result is the the most efficient exploitation of the bandwidth available. Whatever your connection, FlashGet makes sure all of the bandwidth is utilized. Difficult, slow downloads that normally take ages are handled with ease. Download times are drastically reduced.
    Management
    FlashGet is capable of creating unlimited numbers of categories for your files. Download jobs can be placed in specifically-named categories for quick and easy access. The powerful and easy-to-use management features in FlashGet help you take control of your downloads easily.+ much, much more!
    </pre>
    </body>
    </html>