我正在尝试检查两个不同的哈希子串并执行不同的代码。这就是我现在所拥有的:
的Javascript
if(window.location.hash.substring(confirm) {
$('.confirm').click();
}
elseif(window.location.hash.substring(thanks) {
$('.thanks').click();
}
知道我做错了吗?
答案 0 :(得分:3)
使用带引号的indexOf
来表示您要搜索的字符串:
if(window.location.hash.indexOf('confirm') >= 0) {
$('.confirm').click();
}
else if(window.location.hash.indexOf('thanks') >= 0) {
$('.thanks').click();
}
顺便说一下,在原始实施中,您在)
条件下也遗漏了if
。