分享純手寫漂亮的表單驗證
更新時間:2015年11月19日 09:49:56 作者:我_愛編程
最近沒有項目做,閑來沒事,于是自己動手寫了幾個表單驗證,特此分享供大家參考
哈哈 手工饅頭好吃,今天小編跟大家分享手工js表單驗證代碼,感興趣的朋友快來吧。
因為是自定義樣式,所以兼容所有瀏覽器版本,個人認(rèn)為非常漂亮:網(wǎng)址wuxi.rongzi.com
css
<style>
/*tooltip*//* CSS屬性順序按照 字母首字母 排列*/
.ui-slider-tooltip{ background:#fa; border:px solid #fa; color:#fff; display: block; text-align: left; padding: px px px px; position: absolute; z-index:; }
.ui-corner-all { border-radius: px; -moz-border-radius-bottomleft:px; -moz-border-radius-bottomright:px; -moz-border-radius-topleft:px; -moz-border-radius-topright:px; -webkit-border-top-left-radius:px px; -webkit-border-top-right-radius:px px;-webkit-border-bottom-right-radius:px px; -webkit-border-bottom-left-radius:px px;}
.ui-tooltip-pointer-down { border-bottom-width: ; border-left: px dashed transparent; border-right: px dashed transparent; border-top: px solid #fa; bottom: -px; display: block; height:; left: %; margin-left: -px; position: absolute; width:;}
.ui-tooltip-pointer-down-inner { border-left: px dashed transparent; border-right: px dashed transparent; border-top: px solid #fa; left: -px; top: -px; position: absolute; }
.tip{ font-size:pt; line-height:px;}
.error{ border: px solid rgb(, , );}
</style>
前臺:
<input type="text" id="userName"/> <input type="submit" onclick="submitOneClickApply()"/>
js:
function submitOneClickApply() {
var username = $("#userName").val();
if (username == "" || username == "請輸入您的姓名") {
$("#userName").rzAlertTips({ flagInfo: '請輸入聯(lián)系人', isAnimate: true });
}
調(diào)用的js:
<script type="text/javascript">
(function ($) {
jQuery.fn.extend({
rzAlertTips: function (settings) {
$(this).each(function () {
//初始化配置信息
var options = jQuery.extend({
flagCss: "tip",
flagWidth: $(this).outerWidth(),
flagInfo: $(this).attr("title"),
isAnimate: false
},
settings);
if (!options.flagInfo) {
return;
}
$(this).removeAttr("title");
var obj = $(this);
var oToolTip = null;
var fun_show = function () {
//設(shè)置提示信息最小寬度為
options.flagWidth = "auto"; // (parseInt(options.flagWidth) < ) ? : parseInt(options.flagWidth);+ "px"
var oTip = $("<div class='ui-slider-tooltip ui-corner-all' id='tipWrap_" + $(this).attr("id") + "'></div>");
var oPointer = $("<div class='ui-tooltip-pointer-down'><div class='ui-tooltip-pointer-down-inner'></div></div>");
var oTipInfo = $("<div>" + options.flagInfo + "</div>").attr("class", options.flagCss).css("width", options.flagWidth);
//合并提示信息
oToolTip = $(oTip).append(oTipInfo).append(oPointer);
if ($("#tipWrap_" + $(this).attr("id")).length > ) $("#tipWrap_" + $(this).attr("id")).remove();
//添加淡入效果
if (options.isAnimate) {
$(oToolTip).fadeIn("slow");
}
$(obj).after(oToolTip);
//計算提示信息的top、left和width //position.top
var position = $(obj).position();
var oTipTop = eval(position.top - $(oTip).outerHeight() - );
var oTipLeft = position.left;
$(oToolTip).css("top", oTipTop + "px").css("left", oTipLeft + "px");
};
fun_show();
$('.error').removeClass('error');
$(this).addClass("error");
setTimeout(function () { $(oToolTip).remove(); }, );
});
return this;
}
})(jQuery);
</script>
以上內(nèi)容就是小編給大家分享的純手寫漂亮的表單驗證,希望大家喜歡。
相關(guān)文章
在ES5與ES6環(huán)境下處理函數(shù)默認(rèn)參數(shù)的實現(xiàn)方法
本文給大家介紹在ES5與ES6環(huán)境下處理函數(shù)默認(rèn)參數(shù)的實現(xiàn)方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,感興趣的朋友跟隨腳本之家小編一起學(xué)習(xí)吧2018-05-05
javascript得到當(dāng)前頁的來路即前一頁地址的方法
這篇文章主要介紹了javascript得到當(dāng)前頁的來路即前一頁地址的方法,需要的朋友可以參考下2014-02-02
Javascript aop(面向切面編程)之a(chǎn)round(環(huán)繞)分析
這篇文章主要介紹了Javascript aop(面向切面編程)之a(chǎn)round(環(huán)繞) ,需要的朋友可以參考下2015-05-05
使用typescript改造koa開發(fā)框架的實現(xiàn)
這篇文章主要介紹了使用typescript改造koa開發(fā)框架的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02

