开发者

Disable dynamically a jquery plugin

开发者 https://www.devze.com 2022-12-31 01:39 出处:网络
I use 开发者_如何学JAVAthe jquery numeric plugin to allow only numbers to be typed in some fields.

I use 开发者_如何学JAVAthe jquery numeric plugin to allow only numbers to be typed in some fields.

$("input.numeric").numeric();

I want to disable this function dynamically in some cases, to allow the user to type others characters (i.e. letters). I tryed to use the unbind() or undelegate() functions without success.

Does anyone know the solution ? Thanks


This plugin contains function removeNumeric();

And It's almost correct. At first you should add a little fix in jquer.numeric plugin:

insert unbind("keyup", $.fn.numeric.keyup) at removeNumeric function

$.fn.removeNumeric = function()
{
  return this.data("numeric.decimal", null).data("numeric.negative",
  null).data("numeric.callback", null).unbind("keypress",
  $.fn.numeric.keypress).*unbind("keyup",
  $.fn.numeric.keyup)*.unbind("blur", $.fn.numeric.blur);
}

Well, and after that, you could try $("input.numeric").removeNumeric(); Works fine for me.

0

精彩评论

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