如何为内联JQuery按钮设置ID

时间:2019-05-16 17:34:07

标签: jquery

我正在尝试为对话框上的现有按钮分配ID,这些按钮会动态添加到对话框中。

我已经尝试过这些(assign id to jquery dialog button),但是没有用。我正在jsp页面上使用Jquery 1.11.1

<div id='dialog_acknowledgement' title='someTitle' style='display: none;'>
    <span style="text-align:left">
        <p><%=popupMessage%></p>
    </span>
</div>

...

$( 'div#dialog_acknowledgement').dialog( { 
    modal: true, 
    autoOpen: true,
    width: 750,
    position: [ 'center', 'center' ],
    open: function() { jQuery( '.ui-dialog-titlebar-close' ).hide(); },
    close: function() { 
            if ($( 'input[name=acknowledgementAction]' ).val() == "") {
                $( 'input[name=acknowledgementAction]' ).val( "CANCEL" );
            }
            $( "form[name='page_form']" ).submit();
        },
    buttons: {
        "<%=lh.getText("review_jsp_23", LocalizableTag.CONFIG_MESSAGE, "Cancel")%>": function() {   
            $( 'input[name=acknowledgementAction]' ).val( "CANCEL" ); // trying to set the id for these buttons
            $( this ).dialog( "close" );
        },
        "<%=lh.getText("review_jsp_27", LocalizableTag.CONFIG_MESSAGE, "ACKNOWLEDGE")%>": function() {
            $( 'input[name=acknowledgementAction]' ).val( "ACKNOWLEDGE" );
            $( this ).dialog( "close" );
        }
    }
} );

这是我尝试设置ID的选项之一时生成的js

buttons: {
    "Cancel": function() {  
        $(this).attr("id","cancelButton_1");                                
        $( 'input[name=acknowledgementAction]' ).val( "CANCEL" );
        $( this ).dialog( "close" );
        //window.location.href = '../../etm/etmMenu.jsp?selectedTocID=null&parentID=0'
    },
    "ACKNOWLEDGE": function() {
        $( 'input[name=acknowledgementAction]' ).val( "ACKNOWLEDGE" );
        $( this ).dialog( "close" );
    }
}

这是生成的html,看不到id

<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
    <div class="ui-dialog-buttonset">
        <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
            <span class="ui-button-text">Cancel</span>
        </button>
        <button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false">
            <span class="ui-button-text">ACKNOWLEDGE</span>
        </button>
    </div>
</div>

我想为这些按钮添加id,以便将其用于硒测试用例

0 个答案:

没有答案