Relevent HTML:
<p id="baz"></p>
相关代码:
function foo(element) {
element.innerHTML = 'bar';
alert(element.toString() + ' has been modified');
}
foo($('baz'));
此警报“[对象HTMLParagraphElement]已被修改”。有没有办法让“baz被修改”?
答案 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');