Javascript 如何使用Jquery从确认框中的输入框中取消关注用户?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5509467/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to unfocus the cuser from the input box in a confirmation box using Jquery?
提问by Yasitha
I am having a confirmation box with a input field requesting a date. When the confirmation box appears, the input box is in focus. How do I unfocus it? I need to drop down a calendar when I click on the input field. Here is my relevant code:
我有一个带有请求日期的输入字段的确认框。当出现确认框时,输入框是焦点。我如何不对焦?单击输入字段时,我需要下拉日历。这是我的相关代码:
$(".confirmLink").click(function(e) {
e.preventDefault();
var targetUrl = $(this).attr("href");
document.getElementById('dialog').focus();
$("#dialog").dialog({
buttons : {
"OK" : function() {
window.location.href = targetUrl+"/"+"deletedDate"+"/"+document.getElementById('deletedDate').value;
},
"Cancel" : function() {
$(this).dialog("close");
}
}
});
$("#dialog").dialog("open");
});
function datepicker(){
$( "#deletedDate" ).datepicker(
{
dateFormat: 'yy-mm-dd',
changeMonth: true,
changeYear: true,
showAnim: "slideDown"
});
}
回答by Chris McClellan
This should do the trick:
这应该可以解决问题:
.blur();
(as was pointed out - this is sufficient)
(正如所指出的——这就足够了)
回答by Raghav
You can also trigger blur as an event
您还可以将模糊作为事件触发
document.getElementById('dialog').blur();
Or
或者
$('#dialog').blur();
回答by Marcelo Austria
Use blur() event.
使用 blur() 事件。
document.getElementById("dialog").blur();