selectionChanged事件在knockout js中不起作用

时间:2016-04-02 11:23:31

标签: javascript knockout.js knockout-2.0 knockout-3.0

这是我的代码,在本地当我从下拉列表中选择值时,选择了更改事件,但是当我把这个代码放在服务器selectionChanged事件中时没有触发。请帮助我有没有替代方案,我从this URL

找到了这个消息
**HTML Code**

    <select data-bind="options: choices, value: selectedChoice"></select>    
    <select data-bind="event: { change: selectionChanged }">
        <option>A</option>
        <option>B</option>
        <option>C</option>
    </select>

**JS Code:**

    var viewModel = {
        choices: ["one", "two", "three"],
        selectedChoice: ko.observable("two") ,
        selectionChanged: function(event) {
             alert("the other selection changed");  
        } 
    };

    viewModel.selectedChoice.subscribe(function(newValue) {
       alert("the new value is " + newValue); 
    });


    ko.applyBindings(viewModel);

1 个答案:

答案 0 :(得分:0)

问题在于你的jsfiddle url是安全的,而使用过的脚本没有。

如果您转到:http而不是https,则应该

Mixed Content: The page at 'https://fiddle.jshell.net/rniemeyer/LBz6d/show/' was loaded over HTTPS, but requested an insecure script 'http://knockoutjs.com/downloads/knockout-2.2.1.debug.js'. This request has been blocked; the content must be served over HTTPS.