jquery - 如何为内联 JQuery 按钮设置 id
问题描述
我正在尝试将 id 分配给对话框上的现有按钮,这些按钮会动态添加到对话框中。
我已经尝试过这些(将 id 分配给 jquery 对话框按钮)但没有用。我在 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,以便我可以将它们用于我的 selenium 测试用例
解决方案
推荐阅读
- ruby-on-rails - 选择框不显示所选值
- python - 如何运行 gRPC 客户端来测试 tensorflow 模型?
- c# - C# 存储过程函数需要未提供的参数“@id”
- php - 数组未显示来自内爆结果的匹配项
- hadoop - 在 HIVE 表中生成唯一的 bigint 代理键
- oracle-apex - oracle apex 中的柱形图
- for-loop - 如何为回归循环编写本地宏
- javascript - Javascript 正则表达式替换捕获
- java - Eclipse / IntelliJ IDEA 上的 Maven 设置
- python - Python3 http.sever 无效语法