【发布时间】:2017-01-17 12:22:30
【问题描述】:
我将数据插入到 HTML 中,如下所示:
<p each="{this.holidayListFirstPart}" if="{hdate}">
<span id="{description}" onclick={showInputBox}>{hdate}:{description}</span>
</p>
我正在尝试在鼠标点击时将span 标记转换为textarea,以便用户可以像这样编辑文本:
showInputBox(e) {
self.textContent = document.getElementById(e.target.id).innerHTML;
var mySpan = document.getElementById(e.target.id);
var customTextArea = document.createElement("textarea");
customTextArea.id = e.target.id;
customTextArea.setAttribute('onmouseout','{focusGone}');
customTextArea.innerHTML = self.textContent;
mySpan.parentNode.replaceChild(customTextArea, mySpan);
}
focusGone(e){
console.log("lost focus");
}
问题是当用户在编辑文本后离开textarea时,抛出focusGone函数未定义的错误:
Uncaught ReferenceError: focusGone is not defined
如何在 riotjs 中完成这项工作?
【问题讨论】:
-
@Okazari 好的,谢谢!
-
setAttribute设置为{focusGone}时可能不起作用,这不是一个函数,而是某种可能更早运行的模板 -
@adeneo 我用
customTextArea.setAttribute('onmouseout','focusGone()');试过,但也没有用
标签: javascript jquery riot.js riot