简体   繁体   English

JQuery追加在IE9和JQuery 1.7.1中不起作用

[英]JQuery append not working in IE9 and JQuery 1.7.1

I am struggling to integrate this Bootstrap-tag plugin into my app. 我正在努力将此Bootstrap-tag插件集成到我的应用程序中。 It is working fine with jQuery 1.8.3 as you can see it on the GitHub project page . 您可以在GitHub项目页面上看到它,它与jQuery 1.8.3一起正常工作。

My application is using JQuery 1.7.1. 我的应用程序正在使用JQuery 1.7.1。 It works great in Chrome but not in IE (not a surprise). 它在Chrome中效果很好,但在IE中效果不佳(不足为奇)。 I've spent two days now trying to understand why with no luck (I am a jQuery/JS novice). 我花了两天的时间来理解为什么没有运气(我是jQuery / JS新手)。

I created a jsFiddle that captures and shows this error when ran in IE 9. 我创建了一个jsFiddle来捕获并在IE 9中运行时显示此错误。

The specific error is: 具体错误是:

SCRIPT438: Object doesn't support property or method 'append' SCRIPT438:对象不支持属性或方法“追加”

bootstrap-tag.js, line 117 character 5 bootstrap-tag.js,第117行,字符5

And it refers to this line/code: 它引用此行/代码:

$('<span class="tag">')
  .text(value)
  .append($('<button type="button" class="close">&times;</button>')
    .on('click', function () {
      that.remove(that.element.siblings('.tag').index($(this).closest('.tag')))
    })
  )
  .insertBefore(that.element)

QUESTION: Any idea why IE9 is complaining about the append not recognized? 问题:知道为什么IE9抱怨append未被识别吗?

Well, indeed jQuery on older versions do not return the reference to jQuery object after text() function for IE9. 好吧,实际上旧版本的jQuery不会在IE9的text()函数之后返回对jQuery对象的引用。

Basically, the solution was not use the text function and appends the text in the creation of the span. 基本上,解决方案不是使用text函数,而是在创建span时将文本追加。 So I changed to code bellow in bootstrap-tag.js on line 117 that solves the problem. 因此,我在第117行的bootstrap-tag.js中将代码更改为波纹管,从而解决了该问题。

Follows the JS Fiddle Solution 遵循JS小提琴解决方案

Before (IE9 Buggy): 之前(IE9 Buggy):

$('<span class="tag">')
  .text(value)
  .append($('<button type="button" class="close">&times;</button>')
    .on('click', function () {
      that.remove(that.element.siblings('.tag').index($(this).closest('.tag')))
    })
  )
  .insertBefore(that.element)

After (Fixed): 之后(固定):

$('<span class="tag">' + value + '</span>')
    .append($('<button type="button" class="close">&times;</button>')
    .on('click', function () {
      that.remove(that.element.siblings('.tag').index($(this).closest('.tag')))
    })
  )
  .insertBefore(that.element)

Hope it helps. 希望能帮助到你。

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

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