0

我有一个非常奇怪的情况,我正在这样调用我的javascript函数......

window.top.window.stopUpload(<? echo $result; ?>,<? echo $file_name; ?>);

Javascript函数看起来像这样,

function stopUpload(success,filePath){
          var result = '';
          if (success == 1){
             result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
          }
          else {
             result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
          }
          document.getElementById('f1_upload_process').style.visibility = 'hidden';
          document.getElementById('f1_upload_form').innerHTML = result + '<input name="image_file" type="file" class="browse" /><input type="submit" name="submit_button" value="Upload"  class="browse"/>';
          document.getElementById('f1_upload_form').style.visibility = 'visible';     
           
          return true;   
    }

上面的代码不执行stopUpload函数。


但是,如果我这样做,

window.top.window.stopUpload(<? echo $result; ?>);

和像这样的javascript,

function stopUpload(success){
          var result = '';
          if (success == 1){
             result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
          }
          else {
             result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
          }
          document.getElementById('f1_upload_process').style.visibility = 'hidden';
          document.getElementById('f1_upload_form').innerHTML = result + '<input name="image_file" type="file" class="browse" /><input type="submit" name="submit_button" value="Upload"  class="browse"/>';
          document.getElementById('f1_upload_form').style.visibility = 'visible';     
           
          return true;   
    }

只需一个参数,它就可以工作!

问题

为什么它适用于一个参数而不适用于 2?我试过发送普通字符串,'hello'而不是,$file_name但它仍然没有调用。

4

2 回答 2

3

像这样调用你的函数:

window.top.window.stopUpload(<? echo $result; ?>,'<? echo $file_name; ?>');

希望能帮助到你。

于 2012-05-10T11:58:56.777 回答
0

尝试这个 :

window.top.window.stopUpload('<? echo $result; ?>','<? echo $file_name; ?>');

请记住,$result 不应该是任何数值。用户 $result = '1' 代替。

并在 if 语句中更改 success == '1') 。

希望能帮助到你。

于 2020-02-20T23:27:35.197 回答