Mootools的Element构造函数中的HTML? [英] HTML in Mootools' Element constructor?

查看:154
本文介绍了Mootools的Element构造函数中的HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Mootools Element构造函数方法动态地向表中添加一个新行。

  function newPermission somedata){
var newUserPerm = new Element('tr',{
'html':'< td> foo< / td>< td> bar< / td>'
});
newUserPerm.inject('permissions_table');
}

但是,检查生成的代码时,会将以下HTML字符串添加到表格:

 < tr> foobar< / tr> 

我确定还有一些方法可以发送HTML标签,很多在这里,除了另一个问题,其中用户有一个过时的ver。的Mootools ...

解决方案

这已经修复在mootools 1.3 beta和我认为只影响表(否则html setters通过元素构造函数很好) - 在平均而言,不要通过元素构造函数设置html,但在创建TR后设置它:

  var tr = new Element('tr')。inject(document.id(foo)。getElement(tbody),top); 
tr.set(html,'< td> foo< / td>< td> bar< / td>');

这里它的工作方式和你在1.3中一样: http://www.jsfiddle.net/dimitar/ALsBK/



这里是在1.2.4中突破: http://www.jsfiddle.net/dimitar / ALsBK / 1 /



并在1.2.4中使用: http://www.jsfiddle.net/dimitar/ALsBK/2/

I'm currently using the Mootools Element constructor method to dynamically add a new row into a table.

function newPermission(somedata) {
    var newUserPerm = new Element('tr', {
        'html': '<td>foo</td><td>bar</td>'
    });
    newUserPerm.inject('permissions_table');
}

However, upon checking the resulting code, the following HTML string gets added to the table:

<tr>foobar</tr>

I'm sure there's some way to send the HTML tags as well, but I can't find much on it here, except one other question, in which the user had an outdated ver. of Mootools...

解决方案

this has been fixed in mootools 1.3 beta and i think only affects tables (otherwise html setters via element constructors are fine) - in the mean while, do not set the html through the element constructor but set the it after you create the TR:

var tr = new Element('tr').inject(document.id("foo").getElement("tbody"), "top");
tr.set("html", '<td>foo</td><td>bar</td>');

here it is working as you had it in 1.3: http://www.jsfiddle.net/dimitar/ALsBK/

and here it is breaking in 1.2.4: http://www.jsfiddle.net/dimitar/ALsBK/1/

and working in 1.2.4: http://www.jsfiddle.net/dimitar/ALsBK/2/

这篇关于Mootools的Element构造函数中的HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆