<div id="dialogButtons" class="opportunityEditorPopup">
<span id="closed" class="label checkOption" style="display: none;"><input type="checkbox">Mark this as closed</span>
<span class="testButtons" style="display: inline;">
<button id="closeOpportunityButton" class="jqButton imaged ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" title="Close this opportunity" role="button"><span class="ui-button-text">Close</span></button>
<button id="newOrderButton" class="jqButton imaged ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" title="Raise New Quote" role="button"><span class="ui-button-text">New Quote</span></button>
</span>
</div>
所以我目前有以下HTML,我试图在JQuery中引用“closeOpportunityButton”。
然而,我遇到了这个问题,并尝试了以下方法:
$('.testButtons #closeOpportunityButton').click(function(){
console.log("test")
});
和
$('#dialogButtons .testButtons #closeOpportunityButton').click(function(){
console.log("test")
});
两者都不起作用。
想法?
答案 0 :(得分:0)
尝试在您的选择中使用子选择器。以下是代码段:
$('.testButtons > #closeOpportunityButton').click(function(){
console.log("test")
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="testButtons" style="display: inline;">
<button id="closeOpportunityButton" class="jqButton imaged ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" title="Close this opportunity" role="button"><span class="ui-button-text">Close</span></button>
<button id="newOrderButton" class="jqButton imaged ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" title="Raise New Quote" role="button"><span class="ui-button-text">New Quote</span></button>
</span>
&#13;