检查多个哈希子字符串

Check for multiple hash substrings

本文关键字:字符串 哈希 检查      更新时间:2023-09-26

我正在尝试检查两个不同的哈希子字符串并执行不同的代码依赖。这就是我现在拥有的:

爪哇语

if(window.location.hash.substring(confirm) {
    $('.confirm').click();  
}
elseif(window.location.hash.substring(thanks) {
    $('.thanks').click();
}

知道我做错了什么吗?

使用带引号的indexOf来表示要搜索的字符串:

if(window.location.hash.indexOf('confirm') >= 0) {
    $('.confirm').click();  
}
else if(window.location.hash.indexOf('thanks') >= 0) {
    $('.thanks').click();
}

顺便说一句,在您的原始实现中,您在if条件下也缺少)