在我的网站上,如果我的 url 包含单词“test”,我想运行 jQuery 函数
我想做的就是如果我的网址包含“rest”字符串,那么为页面上的元素添加边距?
我添加了一个 jSfiddle 来尝试展示我到目前为止所做的事情。
$(document).ready(function(){
// How can I check to see if my url contains the word 'TEST' then run the below function?
$('.block-widget').css('margin-top, 252px')
});
Use window.location
获取当前位置 url..
根据条件,您可以应用边距顶部属性。
$(document).ready(function(){
var pathname = window.location.pathname;
if(pathname.indexOf('text') > -1){
$('.block-widget').css('margin-top, 252px');
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)