如何通过[id*=“按钮名称”]聚焦按钮
How do I focus a button through [id*= "button name"]
我正试图将注意力集中在一个具有模式的按钮上。我用这行代码成功地做到了这一点:
$("[id*=btnAddEditExecutive]").focus();
问题是每当用户单击一个文本框并单击($("[id*=btnAddEditExecutive]"))
时就会失去焦点。
所以我尝试使用:
document.getElementById("[id*=btnAddEditExecutive]").focus();
但这是行不通的。
请帮忙!谢谢
编辑:我已经相应地编辑了我的代码,但它仍然不起作用。
$("#addEditExecutive").dialog({
modal: true,
width: 800,
appendTo: "form",
open: function () {
$(this).keypress(function (e) {
if (e.which == 13) { // the enter key
$("[id*=btnAddEditExecutive]").click(function () {
// do stuff
})
}
});
},
buttons: {
"Add/Edit Executive Information": function () {
$("[id*=btnAddEditExecutive]").click();
},
"Cancel": function () {
if (confirm("Are you sure you want to cancel ?")) {
//code if yes
$(this).dialog("close");
}
}
},
如果您希望在点击回车键时点击按钮-
$('<your selector>').keypress(function (e) {
if (e.which == 13) { // the enter key
$('[id*=btnAddEditExecutive]').click(function() {
// do stuff
})
}
});
用这行代码解决了这个问题:
$(this).parent().find('.ui-dialog-buttonpane button:first').focus();
$(this).keypress(function (e) {
if (e.keyCode == $.ui.keyCode.ENTER) {
$("[id*=btnAddEditExecutive]").click();
return false;
}
});
将代码更改为这个-$('div[id=nameid]').focus();
或者(如果不起作用)执行-if ($('div').attr('id') == 'nameid') { do something };
相关文章:
- 获取函数中按钮的名称
- 正在获取未选中单选按钮的名称
- 通过 JQuery 指定按钮的名称
- Onclick更改按钮的名称和功能
- 查找选中的单选按钮的名称
- jQuery按类查找单击按钮的名称
- 可以't使用jQuery Popconfirm插件获取点击按钮的名称
- 如何将上传按钮的名称更改为请稍候.
- 如何让IE7使用纯JavaScript更改单选按钮的名称属性
- 在不使用switch语句的情况下按键盘按钮按名称提醒字母
- 如何更改单选按钮列表名称
- 当提交按钮的名称=“提交”时,欧芹表单没有提交
- 通过表单提交特定按钮的名称
- 向数据表列的按钮添加名称
- 在淘汰赛中更改切换按钮的名称
- 使用JQuery查找集合单选按钮组名称
- 获取被单击按钮的名称
- 将字符串传递给jquery对话框以成为按钮的名称
- 如何将c中devexpress mvc 4点击按钮的名称传递给jquery的ajax调用
- 使用 jQuery 在表单中检索提交按钮的名称