【发布时间】:2016-09-26 14:53:06
【问题描述】:
我正在尝试在现有网页中自动填充我无法更改的元素,并且该页面使用Knockoutjs。输入元素或多或少看起来像这样:
<input maxlength="8" id="xxx" data-bind="textInput: otcInput" type="tel">
然后我使用Knockoutjs 尝试取消绑定 textInput 并使用我需要的任何值动态填充输入元素,所以我这样做了:
ko.cleanNode($('#xxx'));
ko.applyBindings({
otcInput: ko.observable("123") // populate myself
});
但是,这会导致错误You cannot apply bindings multiple times to the same element ...问题是为什么?我已经在清理节点了......或者我不是吗?有没有办法使用 knockoutjs 来查看在尝试执行我的“覆盖”ko.applyBindings 时是否存在悬空绑定或剩余物?
我还尝试了其他方法通过JQuery sendkeys plugin 设置输入值但没有成功,即
$('#xxx').sendkeys('123'); // nothing happens
我也试过了:
$('#xxx').unbind();
$('#xxx').off();
$('#xxx').sendkeys('123'); // but again nothing happens
【问题讨论】:
标签: javascript jquery html knockout.js