开发者

JavaScript callback functionality failure

I'm trying to implement the slider functionality I found here. However, I can't seem to get the callback functionality to work correctly. The page that I'm attempting to get it to work on is very simple in that I'm only trying to get it to call a function when the slider value changes: ht开发者_运维百科tp://dev.itap.purdue.edu/dev/sandbox/jfish/slider.html.

I'm assuming I've made some simple javascript error but without much documentation I'm kind of stuck at this point. Any help would be greatly appreciated.


There is an error on line 446 of the fd-slider.js function, where it tries to call each callback function func.call(inp, cbObj);

The cbObj variable is undefined, so the callbacks are not being called. I fixed this by updating those few lines, just to define that var.

for(var i = 0, func; func = callbacks[type][i]; i++) {
    var cbObj = null;
    func.call(inp, cbObj);
};

I couldn't find the callback object definition anywhere in the code.


the callback should point to a function, like the code bellow

callbacks:{"move":[doAlert]}

but instead, you are pointing to the result of the function when you use the () at the end of doAlert. Thats why it is showing the alert when you load the page


Try this?

callbacks:{"move":function(){ doAlert(); }}


the code must be

callbacks:{"move":[doAlert]}


I had the same problem. this should solve your problem:

callbacks:{change:[doalert]}

Know that this library automatically passes through values so if you write your doalert function like

function(fdevent){alert(fdevent.value)}

your alert will say the value your slider is at.

read Callback functions http://www.frequency-decoder.com/2010/11/18/unobtrusive-slider-control-html5-input-range-polyfill/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜