Add events to the DOM
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('')
精彩评论