jquery自定义函数

/**
 *jquery 的拓展方法 
 */
/**
 * 给btn 添加去除disabled
 */
$.fn.disabled = function() {
$(this).each(function(index,em){
var _this = $(em);
if(_this.is('button')||_this.is('input[type="button"]')){
_this.prop('disabled','disabled');
_this.css('cursor','not-allowed');
_this.removeClass('u-btnBlue');
  _this.css({'background': '#1f5183','color': '#fff'});
}else if (_this.is('input')) {
_this.prop('disabled','disabled');
}else if (_this.is('.u-btn')) {
_this.addClass('u-btnDisable');
var _width = _this.outerWidth();
var _height = _this.outerHeight();
var _zIndex = _this.css("z-index");
console.log(parseFloat(_zIndex));
_this.css('position','relative');
var mark = $("<div class='mark'></div>").css({"z-index":_zIndex+1,"width":_width,"height":_height,"opacity":0.5,"top":0,"left":0,"position":"absolute","background-color":"transparent"});
_this.append(mark);
mark.click(function(){
return false;
});
};
});

};



Number.prototype.formatMoney = function(places, symbol, thousand, decimal) {
places = places || 0;
places = !isNaN( places = Math.abs(places)) ? places : 2;
symbol = symbol !== undefined ? symbol : "";
thousand = thousand || ",";
decimal = decimal || ".";
var number = this,negative = number < 0 ? "-" : "", i = parseInt( number = Math.abs(+number || 0).toFixed(places), 10) + "", j = ( j = i.length) > 3 ? j % 3 : 0;
number =  symbol + negative + ( j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand) + ( places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : "");
return number == 0?0:number;
}; 


/**
 * 格式化后转number字符串 
 * @param {Object} symbol 货币标识
 * @param {Object} thousand 分隔符
 * @param {Object} decimal 小数点符号
 */
String.prototype.formatMoneyToNumber = function(symbol, thousand, decimal) {
  var string = this;
  string = string || '0';
  symbol = symbol || "";
  symbol = symbol !== undefined ? symbol : "";
  thousand = thousand || ",";
decimal = decimal || ".";
  return string.replace(symbol, '').replace(new RegExp(thousand,"g"), '').replace(decimal, '.');
};



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
jQuery中,我们可以使用两种方式来添加自定义函数。第一种方式是使用$.fn.extend方法或jQuery.fn来扩展jQuery对象的原型,例如$.fn.extend({'aa':function(){}}) 或 jQuery.fn.aa=function(){}。使用这种方式添加的自定义函数需要通过选择器来调用,例如$("#**").aa()。 另一种方式是使用$.extend方法来直接向jQuery中添加自定义函数,例如$.extend({'aa':function(){}})。使用这种方式添加的自定义函数可以直接通过函数名来调用,例如$.aa()。 通过以上两种方式,我们可以向jQuery中添加自定义的新函数来满足我们的特定需求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [jquery 自定义函数方法](https://blog.csdn.net/a241903820/article/details/80034009)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [【jQuery】如何添加自定义函数及封装自定义插件_09](https://blog.csdn.net/sunyctf/article/details/125665104)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值