2011-04-18 45 views
8

我有下面的代码(见下文),它使字段专注于插入的文本输入。但是这在Firefox中不起作用。所以我无法在Firefox中输入任何文字。Jquery创建文本输入元素并追加形成“字段焦点”在Firefox中不起作用 - 问题

$('<input/>').attr({ type: 'text', id: 'test', name: 'test' }).appendTo('#form'); 

有没有解决这个问题?

提前致谢!

-

修正我的问题

我发现问题是由

$(selector).sortable().disableSelection()

造成我现在已经是不调用

唯一的解决办法

//disableSelection()

任何其他建议都更受欢迎。

+0

你想将焦点设置为输入框? – 2011-04-18 09:39:20

+0

文本输入也不使用jquery load('file.html #form') – user558134 2011-04-18 09:40:18

+0

我也希望能够输入文本字段。如果你不能集中,你不能输入 – user558134 2011-04-18 09:41:23

回答

1

拉升焦点

$('<input/>').attr({ type: 'text', id: 'test', name: 'test'}).appendTo('#form'); 

$('#test').focus(function(e) { 
    alert('Focus'); 
}); 
0

试试下面的代码 -

$('<input/>').attr({ type: 'text', id: 'test', name: 'test', autofocus: 'true' }).appendTo('#form'); 
0

这只是正常的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>