我有一個div,它最初有contenteditable = false。在雙擊它之後將焦點集中在一個可能的div上
<div contenteditable="false" tabindex='1' style="width:100px;height:100px" id="my_div" >def text</div>
我想讓它contenteditable = true and
雙擊後關注它。
function make_focus()
{
$("#my_div").prop('contenteditable','true');
$("#my_div").focus();
}
$(function() {
$("#my_div").dblclick(function(e)
{
make_focus();
})
});
如果我叫make_focus()directly
,沒有這樣
<input type=button value='make focus' onclick="make_focus()">
DblClick事件,然後我得到#my_div集中the way i need
。但是,when i check how it works with dblclick
然後我得到不同的結果。第一件事是雙擊文字後被選中並且i don't need it
。第二件事是in IE the div doesn't get focused after double click
。再次,我希望雙擊就像直接調用的函數一樣工作。 這裏是jsfiddle的鏈接,顯示它應該如何工作 http://jsfiddle.net/cH3Xs/14/。另一個鏈接顯示它不應該工作(請檢查IE)http://jsfiddle.net/Vr8yB/5/
P.S。以下解決方案似乎工作:Text selection in div(contenteditable) when double click