我有以下字符串,我是所有变量的搜索文本顺序,但我想为$(document).ready(function(){
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 500);
return false;
}
}
});
});
和string2
返回true,但string3
应为false。
string1

答案 0 :(得分:0)
你可以这样尝试它会起作用
var string1 = "orders"
var string2 = "orders/pack"
var string3 = "orders/123"
var str = "orders/"
var result = string1.includes(str);
console.log(result)
var result = string2.includes(str);
console.log(result)
var result = string3.includes(str);
console.log(result)
答案 1 :(得分:0)
你可以这样检查:
console.log( string1.includes(str) && (string1 != str) );
答案 2 :(得分:0)
var string1 = "orders"
var string2 = "orders/pack"
var string3 = "orders/123"
var str = "/"
console.log(string1.includes(str)); //false
console.log(string2.includes(str)); //true
console.log(string3.includes(str)); //true
你为什么不使用' /'而不是'订单'?我们不知道的任何边界?