onChange不工作IE8

时间:2014-05-08 07:17:40

标签: javascript jquery internet-explorer-8

我根据每个用户的数量动态创建一个文本区域,为每个用户发表评论。

我使用以下代码执行相同操作,它在除IE8之外的所有浏览器中都能正常工作。

$(template1).find('textarea').attr({"id":'selfasgn'+aud.ASGN_ID,"onchange":'captureSelfComments('+aud.ASGN_ID+')'})

请注意$(template1)是节点中其中一个元素的克隆。

template1 = reviewTemplate.clone(true);

function captureSelfComments(p_asgnid){
  alert('caling captureSelfComments');
}

我尝试了下面的代码,但是当这个元素被构造或附加到DOM时它被调用。所以我把它删除了。

$(template1).find('textarea').live('change',captureSelfComments(aud.ASGN_ID))
我在这里做错了吗?

1 个答案:

答案 0 :(得分:0)

对于IE,请按here所述尝试propertychange(),因为IE可能并不总是支持更改事件。

var lowIE = /msie (6|7|8)/gi.test(window.navigator.userAgent);
$(template1).find('textarea').live(lowIE ? 'propertychange' : 'change',captureSelfComments(aud.ASGN_ID));

一般来说,做用户代理嗅探并不是一个好主意,但我们正在谈论IE ......这基本上也不是一个好主意,一般来说:)