我想区分用户输入的值。
用户使用输入表单来添加值。
如果'#'是用户输入的值的前面。删除'#'并重定向到 A
除了重定向到B
我试图通过使用 charAt() 来区分这一点,但不起作用
我也不知道 .replace() 正在工作
无论我输入什么,该代码只会转到当前 URL + /?。
请帮我
<form>
<input id="pathID" placeholder="Search ..." +
style="height:40px; line-height:40px; padding:0 15px;">
<input onclick="return findSharp()" type="submit"
value="Search" style="background:#222;">
</form>
<script>
function findSharp(){
var stringName = document.getElementById("pathID").value;
if(stringName.charAt(0) == '#'){
findURLA()
} else {
findURLB()
}
}
function findURLA(){
var hashId = document.getElementById("pathID").value;
var hashIdReplace = hashId.replace('#','');
window.location.href =
'http://localhost:8181/activity-2/' + '?' +
'hashtag/' + hashIdReplace;
return false;
}
function findeURLB(){
window.location.href = 'http://localhost:8181/';
document.write("I AM URL B");
return false;
}
</script>
慕姐4208626
慕盖茨4494581
慕村9548890
相关分类