我的其他問題沒有得到一個解決方案,所以我會嘗試與我所做的更改,應該更容易理解和回答。jQuery綁定onclick到父div
我想綁定一個onclick到一個對話框,這是工作。然而,onclick也需要綁定到jQuery圍繞對話框的父div。
open: function()
{
$(this).bind('click', function(){
$('#focusedPatient').val(thiskey);
});
$('div [aria-labelledby="ui-dialog-title-patient_22274"]').bind('click', function(){
$('#focusedPatient').val(thiskey);
});
}
第二個綁定不工作,我猜是因爲我的語法。代碼執行後,它看起來像
<div style="display: block; z-index: 1004; outline: 0px; height: auto;
width: auto; top: 141px; left: 50px;" class="ui-dialog ui-widget ui-widget-content
ui-corner-all ui-draggable" tabindex="-1" role="dialog"
aria-labelledby="ui-dialog-title-patient_22274">
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<span class="ui-dialog-title" id="ui-dialog-title-patient_22274">
<img src="imgs/omButtons/omIcon.png" border="0">
IS0001_LG, Austin Smith, Date Created: NULL, Date Updated: NULL,
Created By: Michael</span>
<div class="ui-dialog-titlebar-buttonpane" style="position: absolute; top: 50%;
right: 0.3em; margin-top: -10px; height: 18px;">
<a href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button"
style="position: static; top: auto; right: auto; margin: 0px;">
<span class="ui-icon ui-icon-closethick">close</span></a>
<a class="ui-dialog-titlebar-maximize ui-corner-all" href="#" role="button" style="">
<span class="ui-icon ui-icon-extlink">maximize</span></a>
<a class="ui-dialog-titlebar-restore ui-corner-all" href="#" role="button"
style="display: none;"><span class="ui-icon ui-icon-newwin">restore</span></a>
<a class="ui-dialog-titlebar-minimize ui-corner-all" href="#" role="button" style="">
<span class="ui-icon ui-icon-minus">minimize</span></a>
</div>
</div>
<div onclick="$('#focusedPatient').val('22274')" id="patient_22274"
style="display: block; width: auto; min-height: 113.375px; height: auto;"
class="ui-dialog-content ui-widget-content ui-dialog-normal" scrolltop="0" scrollleft="0">
第一綁定進入到第三股利和作品,我需要DOM樹爬到div容器這是第二次的onclick綁定。任何人都知道如何使這一個工作?
'$(this).parent()。on('click',function(){...});' – adeneo 2013-02-15 13:17:47
這是一些討厭的HTML。你應該使用[.parent()JQuery函數](http://api.jquery.com/parent/) – 2013-02-15 13:31:33