2011-04-18 43 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>