我只想将下面的jQuery添加到下面的页面。
http://www.mywebsite.com/check-8.asp
http://www.mywebsite.com/edit-8.asp
http://www.mywebsite.com/cart-8.asp这意味着我想把它添加到URL string包含check-8、cart-8或edit-8的地方。
使用jQuery或JavaScript的最佳方式是什么?
var text = $('#system td.td-main').html();
if (text != null)
{
var newtext = text.replace("Pris","<div id=\"pricebox\">Pris").replace("mva\)","mva\)</div>");
$('#system td.td-main').html(newtext);
}提前谢谢。
发布于 2010-08-28 21:50:56
if(location.pathname.indexOf('check-8') > 0 || location.pathname.indexOf('cart-8') > 0 || location.pathname.indexOf('edit-8') > 0){
//your code here
}发布于 2010-08-28 21:52:53
如果需要纯JavaScript解决方案,请使用window.location属性:
if (window.location.href.match(/(check|cart|edit)-8/).length > 0) {
// do your stuff
}可以使用string.match方法检查它是否与正则表达式匹配。如果你需要知道它是哪一个,你也可以把它分解出来:
var matches = window.location.href.match(/(check|cart|edit)-8/);
if (matches.length > 0) {
var action = matches[1]; // will be check, cart or edit
}发布于 2010-08-28 21:54:37
或者,您可以使用以下命令:
function testForCheckEditCart() {
var patt = /(check|edit|cart)-8/i;
return patt.test(location.href);
}https://stackoverflow.com/questions/3590954
复制相似问题