jquery----语法扩展(导入js文件)
简单使用
第一步,新建js文件
第二步,在js文件中添加
$.extend({
"GDP": function () {
console.log("哈哈哈哈");
}
});
第三步,在html中使用
$.GDP() 即可
复杂(1,希望一些函数不可以被外部引用,不可以被修改$)
(function (jq) {
jq.extend({
"GDP":function () {
foo(); //调用内部函数
console.log("带小红花")
}, //可以扩展多个(加上逗号在写几个)
"SGS":function () {
console.log("你蛤蟆")
}
});
function foo() {
console.log("英语八级就是牛")
}
})(jQuery);
(function (jq) {
jq.fn.extend({
"BJG":function () {
foo2();
console.log("就这样吧")
}
});
function foo2() {
console.log("哎哎呀")
}
})(jQuery);
练习----t.js 文件
// 匿名函数
(function (jq) { //jq就相当于$
jq.extend({
"myValidate": function (form) {
var formObj = jq(form) ;//赋一个变量,因为我们经常用到
formObj.find("button").on("click", function () {
console.log("-------------")
formObj.find(".form-group").removeClass("has-error");
formObj.find("span").text("");
formObj.find(":input").each(function () {
if ($(this).val().length === ) {
console.log("")
var name = $(this).prev().text();
$(this).parent().addClass("has-error");
$(this).next().text(name + "不能为空");
return false
}
});
return false
});
}
})
})(jQuery);
tjs
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>作业1</title>
<script src="jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<style>
.container {
margin-top: 50px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<form action="#" novalidate id="login">
<div class="form-group">
<label for="username">用户名</label>
<input type="text" class="form-control" id="username" placeholder="username" required="true">
<span id="helpBlock" class="help-block"></span>
</div>
<div class="form-group">
<label for="Password">密码</label>
<input type="password" class="form-control" id="Password" placeholder="Password">
<span id="helpBlock2" class="help-block"></span>
</div>
<button type="submit" class="btn btn-default submit">提交</button>
</form>
</div>
</div>
</div> <script src="t.js"></script>
<script>
$.myValidate()
</script>
<!--<script>-->
<!--$(".submit").on("click",function () {-->
<!--$("form .form-group").removeClass("has-error");-->
<!--$("form span").text("");-->
<!--$(":input").each(function () {-->
<!--if ($(this).val().length===){-->
<!--var name = $(this).prev().text();-->
<!--$(this).parent().addClass("has-error");-->
<!--$(this).next().text(name+"不能为空");-->
<!--return false-->
<!--}-->
<!--});-->
<!--return false-->
<!--})--> <!--</script>-->
</body>
</html>
html
jquery----语法扩展(导入js文件)的更多相关文章
- vue中如何在本地导入js文件
import {setStore,setUser,getStore,removeStore} from "../../../public/localstory" 在导入js文件时, ...
- Boostrap本地导入js文件
我一般都是用CDN直接导入的,但是有时候需要自己添加一些功能进入,会用到本地导入.关于导入路径问题,做个笔记. 使用HBuilder,首先右键导入相应的js/cs文件 然后是常规——>文件系统 ...
- 向MyEclipse的项目中导入js文件时,出现小红叉
这个问题困扰我很久.刚开始时,也没有解决,因此也在网上寻找解决方法,还是没能解决.最近做项目时再一次出现了这样的问题,于是决定还是再找找办法.在此,分享一下自己的解决方法,给正处于痛苦中的童鞋们带来解 ...
- 使用Jquery promise 动态引入js文件
动态加载一个js得方式很多,如下方式: /** *一般方式加载 */ function normalLoadScript(url) { var node = document.createElemen ...
- 动态导入Js文件
var ScriptLoader = { worker: , isWait: false, readyQueue: [], callback: [], timer: null, wait: funct ...
- 使用jQuery的时候,js文件代码位置规范
/** * 页面加载之后执行的函数:===================================== */$(function() { }); //如果需要同步执行需要同时编写在这里: $( ...
- 自己编写jQuery动态引入js文件插件 (jquery.import.dynamic.script)
这个插件主要是结合jquery或者xhr异步请求来使用的,它可以把已经引入过的js文件记录在浏览器内存中,当下次再引入相同的文件就忽略该文件的引入. 此插件不支持浏览器刷新保存数据,那需要利用cook ...
- 1.在html中引入js文件和Jquery框架
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- jQuery的基础跟JS的正则
大家好,我是唯芸星,这是我的一点点学过的知识,呈现给大家 1:正则表达式 包括: 1:正则表达式包括两部分 ①:定义正则表达式的规则 ②:正则表达式的规模(i/g/ ...
随机推荐
- Python Machine Learning-Chapter4
Chapter4 Building Good Training Sets – Data Preprocessing 4.1 Dealing with missing data 如何判断数据框内的数据是 ...
- VS Code调试Golang提示Failed to continue:Check the debug console for details.
解决方法: 打开调试面板 VSCode->查看->调试 添加调试目标 在"没有调试"的下拉框中点击"添加配置.."添加目标调试配置 在" ...
- 同步、异步、阻塞、非阻塞与future
前言 随着移动互联网的蓬勃发展,手机App层出不穷,其业务也随之变得错综复杂.针对于开发人员来说,可能之前的一个业务只需要调取一次第三方接口以获取数据,而如今随着需求的增加,该业务需调取多个不同的第三 ...
- POJ - 2635 The Embarrassed Cryptographer(千进制+同余模)
http://poj.org/problem?id=2635 题意 给一个大数K,K一定为两个素数的乘积.现给出一个L,若K的两个因子有小于L的,就输出BAD,并输出较小的因子.否则输出GOOD 分析 ...
- vue自学入门-2(vue创建项目)
本人也是刚学习VUE,边找资料,边学习,边给大家分享.1.创建项目 2.启动项目 3.注意上面和下面全部用cnpm
- LINQ to SQL 模拟实现 ROW_NUMBER() OVER(ORDER BY ...) 的功能
Ø 前言 本来是想使用 LINQ 实现类似 SQL: ROW_NUMBER() OVER(ORDER BY -) 的功能,但是貌似 LINQ 不支持,反正没找到解决办法,无奈使用了LINQ Sele ...
- 使用eclipse创建web项目的项目图文步骤
在eclipse中使用maven ① maven插件:eclipse内置 ②maven插件的设置: [1]installations:指定maven核心程序的位置,不建议使用自带的maven程序而应该 ...
- js 运动框架及实例
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- oracle sum(x) over( partition by y ORDER BY z ) 分析
之前用过row_number(),rank()等排序与over( partition by ... ORDER BY ...),这两个比较好理解: 先分组,然后在组内排名. 今天突然碰到sum(... ...
- 数据库之MySQL ERROR 1698 (28000) 错误:Access denied for user 'root'@'localhost'" error【摘抄】
声明:全文均摘抄于MySQL ERROR 1698 (28000) 错误 //错误起源: ~$ mysql -u root -p Enter password: ERROR 1698 (28000): ...