我正在尝试将单击事件绑定到<div />
jQuery 中的新事件。以下代码片段有效(当我单击 div 时,我看到“点击”消息)但是,第二个没有。
谁能告诉我为什么?
工作片段:
'use strict';
(function () {
$(document).ready(function () {
var $display = $('#display'),
$drawingArea = $('<div />')
.attr('id', 'drawing-area')
.click(function() {
alert('clicked');
});
$display.wrap($drawingArea);
})
})();
不工作片段:( 警报“准备”被触发,但不是点击“)
'use strict';
(function () {
$(document).ready(function () {
var $display = $('#display'),
$drawingArea = $('<div />')
.attr('id', 'drawing-area');
$display.wrap($drawingArea);
$drawingArea.ready(function() {
alert('ready');
$drawingArea.click(function() {
alert('clicked');
})
});
})
})();
更新
刚刚尝试了以下方法:
(function () {
$(document).ready(function () {
var $display = $('#display'),
$drawingArea = $('<div />')
.attr('id', 'drawing-area');
$display.wrap($drawingArea);
$drawingArea.ready(function() {
alert('ready');
});
$drawingArea.click(function() {
alert('clicked');
})
})
})();
“就绪”警报触发,但没有“点击”警报。
HTML:
<section id="main">
<svg id="display" xmlns="http://www.w3.org/2000/svg">
</svg>
</section>
更新 2
刚刚注意到,当我用 chrome 开发工具疯狂点击时,在</html
>
<div id="gdx-bubble-container">
<div id="gdx-bubble-main" style="left: 0px; top: 1023.4375px;">
<div id="gdx-bubble-close"></div>
<div id="gdx-bubble-query-container" class="gdx-display-block">
<div id="gdx-bubble-query">not</div>
<div id="gdx-bubble-audio-icon" class="gdx-display-block"></div>
<div id="gdx-bubble-query-container-end"></div>
</div>
<div id="gdx-bubble-meaning">Used with an auxiliary verb or “be” to form the negative</div>
<div id="gdx-bubble-options-tip" class="gdx-display-block">Tip: Didn't want this definition pop-up? Try setting a trigger key in <a href="chrome-extension://mgijmajocgfcbeboacabfgobmjgjcoja/options.html" target="_blank">Extension Options</a>.</div>
<div id="gdx-bubble-attribution" class="gdx-display-none">
<a target="_blank"></a>
<div></div>
</div>
<div id="gdx-bubble-more" class="gdx-display-block"><a target="_blank" href="http://www.google.com/search?q=define+not">More »</a></div>
</div>
<div id="gdx-arrow-container">
<div id="gdx-arrow-main" style="top: 1145.4375px; left: 10px;">
<div id="gdx-bubble-arrow-inner-down"></div>
<div id="gdx-bubble-arrow-outer-down"></div>
</div>
</div>
</div>