在我的网站上,我有一个使用role=button
和Bootstrap的btn btn-primary
的链接。当我尝试将contenteditable
属性分配给按钮时,它无法按预期方式工作,并且不允许我对其进行编辑。
contenteditable
后,使链接按钮聚焦。
答案 0 :(得分:0)
尝试一下:
<button id="editBtn" type="button">Click to edit me</button>
jQuery:
$('#editBtn').on('click', function(e) {
e.preventDefault();
$(this).attr('contenteditable','true');
//$(this).focus();
return;
});
$('#editBtn').on('focus', function(e){
console.log("blurred...");
$(this).attr('contenteditable','false');
});
JS:
document.getElementsById("editBtn").contentEditable = "true";
或
document.getElementsById("editBtn").setAttribute("contenteditable", "true");