如果javascript缺少location.search,则显示警报消息
页面url是如果javascript缺少location.search,则显示警报消息,javascript,jquery,window.location,Javascript,Jquery,Window.location,页面url是example.com/1/page.html?user=123456 需要检查当前页面url是否包含 example.com/1/page.html 没有 ?用户=123456 因为这是动态变量 显示警报消息你好。。通过javascript检查当前url if ( window.location.href = "example.com/1/page.html") { alert("hello"); } 但不起作用 另一个主意 Well window.location.href是
example.com/1/page.html?user=123456
需要检查当前页面url是否包含
example.com/1/page.html
没有
?用户=123456
因为这是动态变量
显示警报消息你好。。通过javascript检查当前url
if ( window.location.href = "example.com/1/page.html") {
alert("hello");
}
但不起作用
另一个主意 Well window.location.href是一个字符串,因此您可以将其视为一个字符串,并执行一些操作以删除URL的查询部分(?位),或者查看字符串包含函数 查看JS indexOf()或split()使用路径名
if ( window.location.pathname = "/1/page.html") {
alert("hello");
}
我会这样做(在?上拆分字符串,如果没有,则不应断开):
与=
或==
非=
(赋值)进行比较
window.location.href=“example.com/1/page.html”
表示window.location.href接受值“example.com/1/page.html”
(甚至不知道是否可以编写此属性)您可以使用window.location.pathname而不是window.location.href`
那只会给你一条路
if ( window.location.href = "/1/page.html") {
alert("hello");
}
它使example.com警报hello&is==不适用于变量?如果(window.location.href.split(“?”[0]==“variable”){alert(“hello”);}对不起,当我点击jsfiddle时,提醒hellow,但我只需要提醒一个example.com/1/page.html不在任何页面上主机代码我跳起来理解我的问题我很抱歉,但你不理解我的答案哦,没有兄弟,但你不理解我的问题,我有一个网站有多个页面,我想让一个页面的事件没有添加js行内,但在indexOK你赢了添加。然后解释我的小提琴是做什么的。这对你来说应该很容易。
if ( window.location.href = "/1/page.html") {
alert("hello");
}