Prototype.js 1.6新元素类和IE> = 9

时间:2012-04-07 20:31:58

标签: prototypejs internet-explorer-9

然后我正在尝试创建一个新元素,例如

new Element('div',{'class':'name'});

所有浏览器都使用“name”类创建一个新元素。但在Internet Explorer 9和10中,我有这个

<div className="name"></div>

如您所见,它创建了className属性而不是class。 我该如何解决这个问题?

3 个答案:

答案 0 :(得分:3)

//This generates 'className':
var popoutControl = new Element('div', {'class':'mySuperCoolClassName'});

// Break the line up into two lines. 
// The following will generate a 'class' attribute instead:
var popoutControl = new Element('div');
popoutControl.className = 'mySuperCoolClassName';

答案 1 :(得分:0)

替换

new Element('div',{'class':'name'});

var mydiv = new Element('div');
mydiv.addClassName('name');

根据http://prototypejs.org/api/element/classNames元素的建议。 ClassName ('name'); 不推荐使用,你应该使用Element。 addClassName ()。

答案 2 :(得分:0)

请在此处查看我的回答:

https://stackoverflow.com/a/20668126/1274995

基本上,Prototype 1.6在那些版本的IE中是错误的。你应该更新Prototype。问题是Element._attributeTranslations.write中包含的翻译列表

Object Element._attributeTranslations.write in Prototype 1.6.0.3

这是Prototype 1.7中的列表(以上,我想)

Element._attributeTranslations.write in Prototype 1.7+

我猜这适用于IE的旧版本(这可能是IE9之前的当前版本)。