简体   繁体   English

在IE 8中调试Javascript

[英]Debugging Javascript in IE 8

I'm trying to debug an issue that I'm only having in IE8. 我正在尝试调试仅在IE8中存在的问题。 It works fine in IE 9+, and chrome. 在IE 9+和chrome中都可以正常工作。 I'm using Aspera to select a file, and am calling a custom function on a callback. 我正在使用Aspera选择文件,并在回调中调用自定义函数。 the function is as follows; 功能如下:

function uploadPathsRecieved(pathsArray) {
   var file_path_selector = '#file_path';
   ...
   $(file_path_selector).text(''); // (*)
   ...
}

On the (*) line, I get an error that file_path_selector is undefined. 在(*)行上,我得到一个错误,指出file_path_selector未定义。 This didn't make much sense to me, so after some playing around to get a feel for the problem, I wound up with the following code: 这对我来说并没有多大意义,因此经过一番摸索来了解问题后,我总结了以下代码:

function uploadPathsRecieved(pathsArray) {
  var x = 3;
  var y = 4;
  var z = x + y;
  z += 2;
  $('#file_path').text(''); // (*)
  ...
}

When I run the program with this code, I still get the error "file_path_selector is undefined" at the (*) line. 当我使用此代码运行程序时,在(*)行上仍然出现错误"file_path_selector is undefined" I'm out of ideas on what the next steps I should take to try and hunt down this problem are. 对于要尝试解决此问题的下一步措施,我没有任何想法。

My gut feeling tells me that there's something being cached, but if I move the (*) line around, the error follows it, and the script window reflects the changes that I make to it. 我的直觉告诉我,正在缓存某些内容,但是如果我移动(*)行,则会出现错误,并且脚本窗口会反映我对其所做的更改。

Here's the Aspera code that's calling my function: 这是调用我的函数的Aspera代码:

function wrapCallbacks(callbacks) {
    return wrapCallback(function() {
      var args, i;
      try {
        args = Array.prototype.slice.call(arguments);
        for ( i = 0; i < args.length; i++) {
          if (isObjectAndNotNull(args[i]) && isDefined(args[i].error)) {
            // error found
            if (isDefined(callbacks.error)) {
              callbacks.error.apply(null, args);
            }
            return;
          }
        }

        // success
        if (isDefined(callbacks.success)) {
          callbacks.success.apply(null, args);
        }
      } catch (e) {
        AW.utils.console.error(e.name + ": " + e.message);
        AW.utils.console.trace();
      }
    });
  }

And here's the entirety of my function, as it exists right now: 这是我目前的全部功能:

var uploadPathsRecieved = function uploadPathsRecieved(pathsArray) {
    //var file_path_selector = '#file_path';
    var x = 3;
    var y = 4;
    var z = x + y;
    z += 2;
    $('#file_path').text('');

    var button_selector = '#select_aspera_file';
    var textbox_selector = '.aspera_textbox';
    /*if (uploadPathsRecieved.fileSelecting == 'cc_file') {
        file_path_selector = '#cc_file_path';
        button_selector = '#select_cc_file';
        textbox_selector = '.cc_aspera_textbox';
    } else if (uploadPathsRecieved.fileSelecting == 'preview_file') {
        file_path_selector = '#preview_file_path';
        button_selector = '#select_preview_file';
        textbox_selector = '.preview_aspera_textbox';
    }*/

    App.AsperaUploadPaths = [];
    if (pathsArray.length == 1) {
        $(button_selector).text("Clear File");
        App.AsperaUploadPaths = pathsArray;
        var error_message = pathsArray[0];
        $(button_selector).parent().children(textbox_selector).text(error_message).removeClass('error');
        //$(file_path_selector).attr('value', pathsArray[0]);
    }
    else 
    {
        var error_message = 'Please select a single file';
        $(button_selector).parent().children(textbox_selector).text(error_message).addClass('error');
    }
}

Solved it. 解决了。 file_path was an <input> , and IE 8 and below doesn't allow you to add text or html to inputs. file_path是<input> ,并且IE 8及以下版本不允许您向输入中添加文本或html。 I fixed it by changing $(file_path_selector).text(''); 我通过更改$(file_path_selector).text('');修复它$(file_path_selector).text(''); to $(file_path_selector).attr('value', ''); $(file_path_selector).attr('value', '');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM