gpt4 book ai didi

javascript - knockout js jquery 范围 slider && 2 输入

转载 作者:行者123 更新时间:2023-11-29 14:58:39 26 4
gpt4 key购买 nike

我需要一些帮助。我有一个代码 http://jsfiddle.net/ZNvWR/19/ .我是 knockout 的新手,我找不到任何解决方案。

那么,如何重写此代码以获取工作输入(更改输入中的值会更改 slider 值)?

<div data-bind="jqSlider: percent, jqOptions: { min: 0, max: 100, range:true }"></div>
<hr/>
Percent: <input data-bind="value: percent()[0]" />
Percent: <input data-bind="value: percent()[1]" />

ko.bindingHandlers.jqSlider = {
init: function(element, valueAccessor, allBindingsAccessor) {
//initialize the control
var options = allBindingsAccessor().jqOptions || {};
$(element).slider(options);

//handle the value changing in the UI
ko.utils.registerEventHandler(element, "slide", function() {
//would need to do some more work here, if you want to bind against non-observables
var observable = valueAccessor();
observable($(element).slider("values"));
});

//handle disposal (if KO removes by the template binding)
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
$(element).slider("destroy");
});
},
//handle the model value changing
update: function(element, valueAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
$(element).slider("values", value);
}
};

var viewModel = {
percent: ko.observableArray([10,50])
};
ko.applyBindings(viewModel)

最佳答案

我只是用一个 slider 帮助一个 SO 用户,它可以像这样改变来做你想做的事

http://jsfiddle.net/N9uwx/3/

<input data-bind="value: min" /><input data-bind="value: max" /><div data-bind="slider: { min: min, max: max }, sliderOptions: {min: 0, max: 100, step: 1}"></div>

关于javascript - knockout js jquery 范围 slider && 2 输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13682691/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com