常见26个jquery使用技巧详解
本文列出jquery一些应用小技巧,比如有禁止右键点击、隐藏搜索文本框文 字、在新窗口中打开链接、检测浏览器、预加载图片、页面样式切换、所有列等高、动态控制页面字体大小、获得鼠标指针的X值Y值、验证元素是否为空、替换元 素、延迟加载、验证元素是否存在于Jquery集合中、使DIV可点击、克隆对象、使元素居中、计算元素个数、使用Google主机上的Jquery类 库、禁用Jquery效果、解决Jquery类库与其他Javascript类库冲突问题。
请看下文jquery技巧:
1、禁止右键点击
(document).ready(function() {
('input.text1'));
});
function textFill(input){ //input focus text function
var originalvalue = input.val();
input.focus( function(){
if( (document).ready(function() {
//Example 1: Every link will open in a new window
$('a[href^="http://"]').attr("target", "_blank");
//Example 2: Links with the rel="external" attribute will only open in a new window
='external']').click(function(){
this.target = "_blank";
});
});
// how to use
<A href="http://huhaiqia.blog.163.com/blog/http://www.opensourcehunter.com" rel=external>open link</A>
4、检测浏览器注: 在版本jQuery 1.4中,.browser 变量。
(document).ready(function() {
jQuery.preloadImages = function()
{
for(var i = 0; i").attr("src", arguments[i]);
}
};
// how to use
(document).ready(function() {
(document).ready(function() {
function equalHeight(group) {
tallest = 0;
group.each(function() {
thisHeight = (document).ready(function() {
equalHeight((".right"));
});
});
8、 动态控制页面字体大小用户可以改变页面字体大小
$(document).ready(function() {
// Reset the font size(back to default)
var originalFontSize = (".resetFont").click(function(){
(".increaseFont").click(function(){
var currentFontSize = ('html').css('font-size', newFontSize);
return false;
});
// Decrease the font size(smaller font)
$(".decreaseFont").click(function(){
var currentFontSize = ('html').css('font-size', newFontSize);
return false;
});
});
9、返回页面顶部功能
(document).ready(function() {
(document).ready(function() {
if ((document).ready(function() {
(document).ready(function() {
window.setTimeout(function() {
// do something
}, 1000);
});
14、 移除单词功能
(document).ready(function() {
if ((document).ready(function() {
(document).ready(function() {
function checkWindowSize() {
if ( (window).resize(checkWindowSize);
});
18、克隆对象
(document).ready(function() {
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", ( (window).scrollTop() + "px");
this.css("left", ( (window).scrollLeft() + "px");
return this;
}
(document).ready(function() {
.expr[':'], {
moreThen1000px: function(a) {
return ('.box:moreThen1000px').click(function() {
// creating a simple js alert box
alert('The element that you have clicked is over 1000 pixels wide');
});
});
20、统计元素个数
(document).ready(function() {
("ul > li").prepend("? ");
// how to use
ul.Replaced { list-style : none; }
});
22、引用Google主机上的Jquery类库Let Google host the jQuery script for you. This can be done in 2 ways.
//Example 1
<SCRIPT src="http://huhaiqia.blog.163.com/blog/http://www.google.com/jsapi"></SCRIPT>
<SCRIPT type=text/javascript>
google.load("jquery", "1.2.6");
google.setOnLoadCallback(function() {
// do something
});
</SCRIPT><SCRIPT src="http://huhaiqia.blog.163.com/blog/http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type=text/javascript></SCRIPT>
// Example 2:(the best and fastest way)
<SCRIPT src="http://huhaiqia.blog.163.com/blog/http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type=text/javascript></SCRIPT>
23、禁用Jquery(动画)效果
(document).ready(function() {
var jq('#id').show();
});
出处:http://www.cnblogs.com/ajunForNet/p/3529638.html
关注我】。(●'◡'●)
如果,您希望更容易地发现我的新博客,不妨点击一下绿色通道的【因为,我的写作热情也离不开您的肯定与支持,感谢您的阅读,我是【Jack_孟】!
本文来自博客园,作者:jack_Meng,转载请注明原文链接:https://www.cnblogs.com/mq0036/p/7008360.html
【免责声明】本文来自源于网络,如涉及版权或侵权问题,请及时联系我们,我们将第一时间删除或更改!
posted on 2017-06-14 13:35 jack_Meng 阅读(2484) 评论(0) 编辑 收藏 举报
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器
2015-06-14 bat echo 输出不同的文字颜色和背景色
2014-06-14 Eclipse添加中文javadoc