【发布时间】:2015-03-13 00:41:54
【问题描述】:
无法将双向数据绑定附加到<div contenteditable> 标记。 Here is the demo
html:
<body>
<div contenteditable style="height:40px;min-width:40px">{{content}}</div>
</body>
js:
if (Meteor.isClient) {
Session.setDefault('content', 'Try to edit me')
Template.body.helpers({
content: function () {
return Session.get('content')
}
})
Template.body.events({
'keydown div': function (e) {
setTimeout(function(){ Session.set('content', $(e.target).text()) })
}
})
}
在 github 上也有一个 open issue。
【问题讨论】:
-
试试blur事件,它会在你失去对div的关注后保存内容
-
@Sindis 可以工作,但最好让它在 keydown 上工作:-\
-
event.keyCode怎么样,在Session中添加char keyCode即可
标签: javascript html meteor