没有合适的资源?快使用搜索试试~ 我知道了~
本文实例总结了经典且实用的jQuery代码开发技巧。分享给大家供大家参考。具体如下: 1. 禁止右键点击 $(document).ready(function(){ $(document).bind("contextmenu",function(e){ return false; }); }); 2. 隐藏搜索文本框文字 Hide when clicked in the search field, the value.(example can be found below in the comment fields) $(document).ready(function() { $
资源推荐
资源详情
资源评论
jQuery实用技巧必备(上)实用技巧必备(上)
本文实例总结了经典且实用的jQuery代码开发技巧。分享给大家供大家参考。具体如下:
1. 禁止右键点击禁止右键点击
$(document).ready(function(){
$(document).bind("contextmenu",function(e){
return false;
});
});
2. 隐藏搜索文本框文字隐藏搜索文本框文字
Hide when clicked in the search field, the value.(example can be found below in the comment fields)
$(document).ready(function() {
$("input.text1").val("Enter your search text here");
textFill($('input.text1'));
});
function textFill(input){ //input focus text function
var originalvalue = input.val();
input.focus( function(){
if( $.trim(input.val()) == originalvalue ){ input.val(''); }
});
input.blur( function(){
if( $.trim(input.val()) == '' ){ input.val(originalvalue); }
});
}
3. 在新窗口中打开链接在新窗口中打开链接
XHTML 1.0 Strict doesn’t allow this attribute in the code, so use this to keep the code valid.
$(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
$('a[@rel$='external']').click(function(){
this.target = "_blank";
});
});
// how to use
<a href="http://www.jb51.com" rel=external>open link</a>
4. 检测浏览器检测浏览器
注: 在版本jQuery 1.4中,$.support 替换掉了$.browser 变量
$(document).ready(function() {
// Target Firefox 2 and above
if ($.browser.mozilla && $.browser.version >= "1.8" ){
// do something
}
// Target Safari
if( $.browser.safari ){
// do something
}
// Target Chrome
if( $.browser.chrome){
// do something
}
// Target Camino
if( $.browser.camino){
// do something
}
资源评论
weixin_38569166
- 粉丝: 7
- 资源: 878
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功