JQuery自动为外部链接添加target=“blank”属性
在链接至外部站点时,大家可能希望使用target=”blank”属性以确保在新的选项卡中打开页面。问题在于,target=”blank”属性并未经过W3C认证。jQuery能够帮上大忙:以下片段能够检测当前链接是否指向外部,如果是则自动为其添加target=”blank”属性。var root = location.protocol + “//” + location.host;$(“a”).no
不怂!!
在链接至外部站点时,大家可能希望使用target=”blank”属性以确保在新的选项卡中打开页面。问题在于,target=”blank”属性并未经过W3C认证。jQuery能够帮上大忙:以下片段能够检测当前链接是否指向外部,如果是则自动为其添加target=”blank”属性。var root = location.protocol + “//” + location.host;$(“a”).no
又是另一项“经典”效果,大家可以利用以下片段随时加以运用。$(document).ready(function() { $(“.thumbs img”).fadeTo(“slow”, 0.6); // This sets the opacity of the thumbs to fade down to 60% when the page loads $(“.thumbs img”).hover
无论是电子邮件、用户名还是密码,很多常见字段都不需要使用空格。以下代码能够轻松禁用选定输入内容中的全部空格。$(“input.nospace”).keydown(function(e) { if (e.keyCode == 32) { return false; }});
[code lang=”js”]location.href = history.go(-1);location.reload();[/code]
var content += ”
“;$(“#errorArea”).val(content);
//写法一location.href = location.href;//写法二location.reload();
//判断是否为空$.trim(” hello worl d! ”).length
//第1种写法 function Circle(r) { this.r = r; } Circle.PI = 3.14159; Circle.prototype.area = function() { return Circle.PI * this.r * this.r; } var c = new Circle(1.0); alert(c.area());
$(“#title”).focus();