Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript可以在Firefox中使用,但不能在Chrome或IE中使用_Javascript_Internet Explorer_Google Chrome_Firefox_Spiceworks - Fatal编程技术网

Javascript可以在Firefox中使用,但不能在Chrome或IE中使用

Javascript可以在Firefox中使用,但不能在Chrome或IE中使用,javascript,internet-explorer,google-chrome,firefox,spiceworks,Javascript,Internet Explorer,Google Chrome,Firefox,Spiceworks,我正在为Spiceworks开发一个插件,用于重新格式化文本块。不幸的是,它只适用于Firefox,而不适用于Chrome或IE plugin.includeStyles(); function log(msg) { throw new Error(msg); } SPICEWORKS.app.helpdesk.ticket.ready(function(){ console.log('###Start function###'); console.log('###URL###');

我正在为Spiceworks开发一个插件,用于重新格式化文本块。不幸的是,它只适用于Firefox,而不适用于Chrome或IE

plugin.includeStyles();
function log(msg) {
  throw new Error(msg);
}
SPICEWORKS.app.helpdesk.ticket.ready(function(){
  console.log('###Start function###');
  console.log('###URL###');
  var url = jQuery("li.custom")[2].lastElementChild.firstChild.wholeText;

  //Check to see if category is project.
  for(var i=0;i<jQuery("li.custom").length;i++)
  {
    if (jQuery("li.custom")[i].lastElementChild.firstChild.wholeText == "Project")
    {
        for(var u=0;u<jQuery("li.custom").length;u++)
        {
          if (jQuery("li.custom")[u].lastElementChild.firstChild.wholeText.contains("http"))
          {
            jQuery("li.custom")[u].innerHTML = '<a href="'+url+'" target="_blank"><span class="projectLink">Project Link</span></a>';
          }
       }
    }
  }
});​
Chrome显示有一个错误Uncaught TypeError:无法读取第9行变量url=


如何使不同浏览器的显示一致?

听起来Firefox与IE和Chrome中的li元素数量不同,因为jQueryli.custom[2]在这些浏览器中没有定义,但在Firefox中显然没有定义。你能在所有浏览器中检查jQueryli.custom.length吗,就在有问题的行之前?刚刚检查了jQueryli.custom.length,所有浏览器中它都解析为3。刚刚解决了我自己的问题。出于某种原因,lastElementChild.firstChild.wholeText在IE&Chrome下为空,但如果我将其更改为lastElementChild.innerHTML,则在每个浏览器下都可以正常工作。我还必须将lastElementChild.firstChild.wholeText.containshttp更改为lastElementChild.innerHTML.indexOfhttp!==-1以使其正常工作。