use*_*880 0 html javascript jquery
我试图找到一个列表元素双击时可编辑的最佳方法.如果我有这样的设置:jsfiddle
HTML
<ul>
<li>Hello</li>
<li>World</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
JS
$('li').dblclick(function() {
//something here?
});
Run Code Online (Sandbox Code Playgroud)
什么是编码双击动作的最佳方法,让我更改单击列表元素的值?
$('li').dblclick(function() {
this.contentEditable=true
$(this).on('keypress blur', function(e) {
if(e.keyCode&&e.keyCode==13||e.type=='blur'){
this.contentEditable=false
return false
}
});
$(this).focus()
});
Run Code Online (Sandbox Code Playgroud)
编辑
增加焦点().thx @ L105