从$('elementname')中检索'elementname'?

时间:2011-06-28 13:59:30

标签: mootools element

Relevent HTML:

<p id="baz"></p>

相关代码:

function foo(element) {
    element.innerHTML = 'bar';
    alert(element.toString() + ' has been modified');
}

foo($('baz'));

Relevent jsfiddle

此警报“[对象HTMLParagraphElement]已被修改”。有没有办法让“baz被修改”?

2 个答案:

答案 0 :(得分:1)

试试这个,用.get('id')

替换element.toString()
function foo(elementname) {
    elementname.set("html", 'bar');
    alert(elementname.get('id') + ' has been modified');
}

foo('baz');

答案 1 :(得分:0)

function foo(elementname) {
    $(elementname).innerHTML = 'bar';
    alert(elementname + ' has been modified');
}

foo('baz');