如果我添加一个额外的参数,为什么不调用javascript函数

时间:2012-05-10 11:54:49

标签: php javascript function parameters parameter-passing

我有一个非常奇怪的情况,我正在调用我的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,但仍然无法调用。

2 个答案:

答案 0 :(得分:3)

按照以下方式调用您的函数:

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

希望它有所帮助。

答案 1 :(得分:0)

尝试一下:

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

请记住,$ result不应为任何数值。用户$ result ='1'。

在if语句中更改成功=='1')

希望有帮助。