Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一些使用 jQuery 可调整大小的 div。我想要做的是以某种方式将 div 的高度分配给敲除属性,因此当高度改变时,值将保存在敲除模型中。我考虑过使用“css”或“attr”绑定来做到这一点,有什么想法吗?
在您的绑定中,您可以使用 jQuery 事件,例如:
data-bind="event:{'resize':sizeChanged}"
我已经调整了你的例子。
请尝试 示例
css、attr 绑定不是真正的“双向”绑定,例如当 DOM 中的宽度和高度发生变化时,模型会更新。
有一个jQuery 插件可以绑定 resize 事件。
监听此事件并更改模型的属性。这里有一个小提琴。