0

This issue is specifically with Safari.

<div id="list">
    <ul>
        <li onclick="do_something();"><!-- block with stuff in it --></li>
    </ul>
</div>

When the above is loaded normally, the onclick applies to the entire li block. The problem is, later on when I use ajax to populate the #list div dynamically...

$("#list").html('<ul><li onclick="do_something();"><!-- block with stuff in it --></li></ul>');

The click event doesn't fire on the entire block but only the part of the block (i.e. the part of the block where content does not exist, the background).

4

2 回答 2

2

那很奇怪。您可以为此使用 jquery 事件:

$("#list")
    .empty()
    .append ( $('<ul><li><!-- block with stuff in it --></li></ul>' )
        .find('li')
        .click(dosomething)
        .end()
    );
于 2010-01-03T18:18:16.970 回答
0

出于奇怪的安全原因,您不能在使用 innerHTML 属性时使用 onclick(这正是 html() 所做的)。您需要使用 addEvent(mootools) 附加事件 -> 在 jquery 中找到一些相关方法

于 2010-01-03T18:27:35.423 回答