2

所以我认为我用我的 jquery 移动滑块做的一切都是正确的,但是控件没有被重新启用。我用它做了一个相当不错的 jsFiddle,希望有人能很快发现错误。

在小提琴上,您将看到 jQuery moblie 控件。如果单击并移动滑块位置,该事件将触发控件值更改。如果您最终在 20 秒内更改值超过 5 次,则控件将锁定。您可以将其视为冷却时间。控制冷却后,它应该重新启用以进行更多的糖化。

问题是,控件永远不会从被禁用中恢复过来!

http://jsfiddle.net/Narq6/

示例 Javascript:

var sent = 0;
var disabled = false;

$('#slider-fill').on( 'slidestop', function()
                     {
                       send();
                       writeConsole(sent);                                           
                     })

function send()
{
 setTimeout(decrease, 4000);
    sent +=1;

  if(sent > 5)
  {
     $('#slider-fill').prop('disabled', 'disabled');

    disabled = true;
  }  
}
function decrease()
{
  if(sent > 0)
     sent -= 1;
 writeConsole('decrease'); 
 writeConsole(sent); 

  if(sent === 0)
  {
    //CODE TO DISABLE HERE!!!
    //LOOK HERE THIS IS WHERE I REMOVE THE DISABLE!!!
      writeConsole('no longer disabled!');     
     $('#slider-fill').prop('disabled', '');
    ///YOU LOOKED TOO FAR GO BACK A LITTLE BIT :D
  }
}

function writeConsole(message)
{
  var miniconsole = $('#miniConsole');
  var contents = miniconsole.html();
  miniconsole.html(contents + message + '<br/>' );
  miniconsole.scrollTop(10000);

}
4

1 回答 1

2

You were using incorrect enable/disable syntax.

This one is a coorect syntax:

$('#slider-fill').slider('disable');

and

$('#slider-fill').slider('enable');

Here's am working example made from your jsFiddle: http://jsfiddle.net/Gajotres/djDDr/

于 2013-01-12T22:49:06.310 回答