Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在用 jquery 创建一个列表
$('<li value="0" onclick="'if(cond){ }'"> </li>).appendTo('#ul list');
问题出在 onclick 部分,有人可以告诉我正确的语法吗?
既然你使用jQuery,那么就不要使用onclick属性。
onclick
$('<li>').attr('value', '0').click(function() { if (cond) { //... } }).appendTo('#ul list');