admin管理员组文章数量:1357387
I am building a HTML5 webapp and I tried using contenteditable feature to make a in-place edit of text,but for some reason I couldn't get "editing" to work.
EDIT: I am using Chrome 12.0.xx
- It highlights the Element(I can see it by CSS)
- I also tested
object.isContentEditable
which returnstrue
- I tried changing
<lable>
to other elements like<div>
,<p>
,<span>
nothing works.Only<textarea>
works but I am guessing that has got nothing to do with HTML5 or contenteditable attribute. blur
event gets fired on exit of edit mode.(I can see from debugger)
With some clue in question How do I figure out why the contenteditable attribute doesn't work? I tried turning off of all CSS but no luck.
The only thing is, I am adding my elements via javascript rather that HTML source
JS Code:
var newLi =document.createElement("li");
var newLable=document.createElement("lable");
newLable.className="labletext";
newLable.contentEditable="true";
newLable.innerText=String(localStorage["task."+i+".taskValue"]);
newLable.addEventListener('blur',editTask,false);
newLi.appendChild(newLable);
Parent.appendChild(newLi);
function editTask()
{
var keyid=this.id;
var startchar = keyid.lastIndexOf("_");
var endchar=keyid.length;
var taskId=parseInt(keyid.substring(startchar+1,endchar));
localStorage.setItem("task."+taskId+".taskValue",this.innerText);
loadTasks("tasklist");
}
I am building a HTML5 webapp and I tried using contenteditable feature to make a in-place edit of text,but for some reason I couldn't get "editing" to work.
EDIT: I am using Chrome 12.0.xx
- It highlights the Element(I can see it by CSS)
- I also tested
object.isContentEditable
which returnstrue
- I tried changing
<lable>
to other elements like<div>
,<p>
,<span>
nothing works.Only<textarea>
works but I am guessing that has got nothing to do with HTML5 or contenteditable attribute. blur
event gets fired on exit of edit mode.(I can see from debugger)
With some clue in question How do I figure out why the contenteditable attribute doesn't work? I tried turning off of all CSS but no luck.
The only thing is, I am adding my elements via javascript rather that HTML source
JS Code:
var newLi =document.createElement("li");
var newLable=document.createElement("lable");
newLable.className="labletext";
newLable.contentEditable="true";
newLable.innerText=String(localStorage["task."+i+".taskValue"]);
newLable.addEventListener('blur',editTask,false);
newLi.appendChild(newLable);
Parent.appendChild(newLi);
function editTask()
{
var keyid=this.id;
var startchar = keyid.lastIndexOf("_");
var endchar=keyid.length;
var taskId=parseInt(keyid.substring(startchar+1,endchar));
localStorage.setItem("task."+taskId+".taskValue",this.innerText);
loadTasks("tasklist");
}
Share
Improve this question
edited May 23, 2017 at 12:32
CommunityBot
11 silver badge
asked Jun 12, 2011 at 22:51
Pavan KeerthiPavan Keerthi
1,6914 gold badges18 silver badges22 bronze badges
4
-
You don't need to supply the second argument to
substring
if you want to go to the end of the string. Justkeyid.substring(startchar+1)
is good. – Šime Vidas Commented Jun 12, 2011 at 23:07 -
You know that
addEventListener
doesn't work in IE8, right? – Šime Vidas Commented Jun 12, 2011 at 23:09 -
You know that
innerText
doesn't work in Firefox, right? – Šime Vidas Commented Jun 12, 2011 at 23:10 - Hi,thanks for letting me know.I changed code.Also,I am focusing on making this app for chrome, so IE8 is not issue for me right now.I will keep that in mind. – Pavan Keerthi Commented Jun 12, 2011 at 23:13
2 Answers
Reset to default 4It's
document.createElement('label')
not 'lable'
Live demo: http://jsfiddle/XuAfA/1/
The demo shows that the LABEL is editable.
For anyone ing later here,I Found the issue.I also enabled draggable attribute on <li>
hence click event is hijacked by <li>
events before reaching <label>
child. Its answered here How can I enable 'draggable' on a element with contentEditable?.
本文标签: javascriptHTML5 ContentEditable not working in ChromeStack Overflow
版权声明:本文标题:javascript - HTML5 ContentEditable not working in Chrome - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744040921a2580646.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论