(非常新的JavaScript jQuery)if语句语法在JavaScript jQuery。每个函数
if语句是否可以包含其他函数的集合,特别是.each函数?如果是的话,我的实施有什么问题吗?
var string2 = "domain";
var mainpath = (window.location.href);
if (mainpath.indexOf(string2)) {
$("#topnav a").each(function(){
var thishref = $(this).attr('href');
$(this).attr({href: thishref + '?lnkid=tnav'});
});
$("#nav a").each(function(){
var thishref = $(this).attr('href');
$(this).attr({href: thishref + '?lnkid=pnav'});
});
}
我想要做的是只在页面位于我的域(而不是在cms的开发空间内)时才在if语句内运行代码。 - 感谢
不严格有关你的问题,但你可以直接比较'window.location.host' – Gareth 2010-12-10 15:07:14
if语句可以包含任何其他语句,例如块语句,它又包含一个零或多个语句的列表。 – 2010-12-10 15:20:00