HTML in Mootools' Element constructor?

会有一股神秘感。 提交于 2019-12-11 06:34:56

问题


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...


回答1:


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/



来源:https://stackoverflow.com/questions/3494971/html-in-mootools-element-constructor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!