Jquery 创建文本输入元素并附加到表单“字段焦点”在 Firefox 中不起作用 - 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5700961/
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
Jquery create text input element and append to form "field focus" does not work in Firefox -problem
提问by user558134
I have the following code (see below) which makes the field focus on the inserted text input. But this does not work in Firefox. So I cannot type any text in Firefox.
我有以下代码(见下文),它使该字段专注于插入的文本输入。但这在 Firefox 中不起作用。所以我无法在 Firefox 中输入任何文本。
$('<input/>').attr({ type: 'text', id: 'test', name: 'test' }).appendTo('#form');
Is there any fix for this?
有什么解决办法吗?
Thanks in advance!
提前致谢!
--
——
Correction to my question
更正我的问题
I found out that the problem is caused by
我发现问题是由
$(selector).sortable().disableSelection()
$(selector).sortable().disableSelection()
The only resolution I have now is to not call
我现在唯一的解决办法就是不打电话
//disableSelection()
//disableSelection()
Any other suggestions are more then welcome.
任何其他建议更受欢迎。
回答by Abhay Yadav
try for focus
尝试集中注意力
$('<input/>').attr({ type: 'text', id: 'test', name: 'test'}).appendTo('#form');
$('#test').focus(function(e) {
alert('Focus');
});
回答by user3763367
Try the below code -
试试下面的代码 -
$('<input/>').attr({ type: 'text', id: 'test', name: 'test', autofocus: 'true' }).appendTo('#form');
回答by Webomatik
This works just fine with Firefox 45:
这适用于 Firefox 45:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Javascript/jQuery Tests</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.3.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
$('<input/>').attr({ type: 'text', id: 'test', name: 'test' }).appendTo('#myForm').focus();
});
</script>
</head>
<body>
<form name="myForm" id="myForm" method="post"></form>
</body>
</html>