2014-01-05 46 views
0

我有我的頁面中使用jQuery插件的結果生成以下的HTML。jQuery找到確定按鈕

我想找到使用jQuery的確定按鈕,然後添加一些javascript到這個按鈕的點擊事件。

我該怎麼做?

<div class="ui-dialog-buttonset"> 
    <button class="dnnPrimaryAction" type="button">Ok</button> 
</div> 

編輯1:

完整的HTML這是我的網頁上dnnAlert是如下(dnnAlert是DNN一個jQuery UI的警告對話框實現)。

<div tabindex="-1" class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-front dnnFormPopup ui-draggable ui-dialog-buttons" role="dialog" aria-describedby="ui-id-3" aria-labelledby="ui-id-4" style="left: 810px; top: 816.39px; width: 300px; height: auto; display: block;"> 
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"><span class="ui-dialog-title" id="ui-id-4">Copy Successful</span><button class="ui-dialog-titlebar-close"></button></div> 
<div class="dnnDialog ui-dialog-content ui-widget-content" id="ui-id-3" style="width: auto; height: auto; display: block; min-height: 0px; max-height: none;">Copied code to clipboard</div> 
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"> 
    <div class="ui-dialog-buttonset"><button class="dnnPrimaryAction" type="button">Ok</button> </div> 
</div> 
</div> 

回答

3

沒有看到其他的HTML我會選擇儘可能具體:

$("button.dnnPrimaryAction:contains('Ok')").click(function(){ 
    //do something 
}); 

JS小提琴:http://jsfiddle.net/aVFV5/

+0

我在我的文章中添加了編輯1下的詳細html。 – Sunil

0

使用ID。

<button class="dnnPrimaryAction" type="button" id = "okButton">Ok</button> 

$(".ui-dialog-buttonset #okButton").click(function() { 
    alert("Handler for .click() called."); 
});