开发者

Add events to the DOM

开发者 https://www.devze.com 2023-03-27 23:58 出处:网络
I have a trouble creating the DOM: { ... DOM = DOM + \'<td colspan=\"3\" align=\"center\">\'; DOM = DOM + \'<div id=\"primero\" onClick(imprimir());> plz </div>\';

I have a trouble creating the DOM:

{
    ...
    DOM = DOM + '<td colspan="3" align="center">';
    DOM = DOM + '<div id="primero" onClick(imprimir());> plz </div>';
    DOM = DOM + '</td>';
    ...
    $('#test').html(DOM);
}

function imprimir() {
    console.log('开发者_JAVA技巧 ready!');
}

but that onclick doesn't work. Any ideas?


You are missing an = in your onclick definition. Try like this:

DOM = DOM + '<div id="primero" onclick="imprimir();">plz</div>';


DOM = DOM + '<div id="primero" onClick="imprimir();"> plz </div>';


Don't recommend playing with the dom like this. No need for hand quoting all those HTML tags and your asking for an error if you do it alot. Recommend you use:

document.createElement('')

setAttribute('', '')

document.getElementById('').appendChild('')

0

精彩评论

暂无评论...
验证码 换一张
取 消