TJF框架中增加數量加減控件

天遠(yuǎn)科技  發表于:2015-08-14  分(fēn)類:HTML/JS/CSS相關(guān)  閱讀(7032)  贊同30

随着互聯網的發展,界面的要求逐漸提高,HTML基礎控件已經不能(néng)勝任,不論基于界面的友好(hǎo)(hǎo)度也(yě)好(hǎo)(hǎo),還是網站(zhàn)制作(zuò)過程中得難易度也(yě)好(hǎo)(hǎo),桐鄉天遠(yuǎn)科技結合多年來(lái)的網站(zhàn)制作(zuò)經驗,開發了(le)一(yī)套JS框架,試圖讓界面渲染開發的速度更快(kuài),以下(xià)是框架中的開關(guān)控件實現(xiàn)。

$.fn.extend({
TY_Spinner:function(ismini) {
var myClass = 'TYF_spinner';
if(ismini == 1) {
myClass = 'TYF_mspinner';
}
return $(this).each(function(){
if($(this).attr("type")=="text" && (TY.Text.isfloat($(this))!=true || TY.Text.isint($(this))!=true)) {
var width = 60;
if($(this).attr("min")) var minValue = $(this).attr("min");
if($(this).attr("max")) var maxValue = $(this).attr("max");
if($(this).attr("width")) width = $(this).attr("width");
var mySpinnerHtml = "<span class=\""+myClass+"\" style=\"width:"+width+"px\"><input type=\"text\" name=\""+$(this).attr("name")+"\" id=\""+$(this).attr("id")+"\" value=\""+$(this).val()+"\" style=\"width:";
if(ismini==1) {
mySpinnerHtml += width*1-17;
}else{
mySpinnerHtml += width*1-22;
}
mySpinnerHtml += "px\" />";
mySpinnerHtml += "<span class=\"TYF_spinner_bn\"><span class=\"TYF_spinner_bnup\"></span><span class=\"TYF_spinner_bndown\"></span></span></span>";
var sObj = $(mySpinnerHtml);
$(this).before(sObj);
$(this).remove();
sObj.find(".TYF_spinner_bnup").mousedown(function(){
var _textValue = 0;
if(TY.Text.isint(sObj.children("input")) && TY.Text.isfloat(sObj.children("input"))) {

}else{
_textValue = sObj.children("input").val();
}
if(maxValue) {
if(_textValue*1<maxValue*1) {
sObj.children("input").attr("value",_textValue*1+1);
}
}else
sObj.children("input").attr("value",_textValue*1+1);
});
sObj.find(".TYF_spinner_bndown").mousedown(function(){
var _textValue = 0;
if(TY.Text.isint(sObj.children("input")) && TY.Text.isfloat(sObj.children("input"))) {

}else{
_textValue = sObj.children("input").val();
}
if(minValue) {
if(_textValue*1>minValue*1) {
sObj.children("input").attr("value",_textValue*1-1);
}
}else
sObj.children("input").attr("value",_textValue*1-1);
});
}
});
}
});

前台調用隻需$(id).TY_Spinner();




在線聯系
點擊這(zhè)裏給我發消息
點擊這(zhè)裏給我發消息
關(guān)注我們