Javascript 按钮将文本从文本框传递到jsp中的href调用
我试图允许用户单击按钮,然后在文本框中获取值并将其添加到href调用的末尾。我目前有一个将两个字符串添加在一起并调用href的函数,但当单击按钮时,似乎什么也没有发生。以下是我目前得到的信息:Javascript 按钮将文本从文本框传递到jsp中的href调用,javascript,html,href,Javascript,Html,Href,我试图允许用户单击按钮,然后在文本框中获取值并将其添加到href调用的末尾。我目前有一个将两个字符串添加在一起并调用href的函数,但当单击按钮时,似乎什么也没有发生。以下是我目前得到的信息: <!DOCTYPE html> <html> <head> <script> function findAccountID() { var text = document.getElementById('textInput');
<!DOCTYPE html>
<html>
<head>
<script>
function findAccountID() {
var text = document.getElementById('textInput');
var value = encodeURIComponent(text.value); //encode special characters
location.href = '**href path here**'+value; //goto URL
}
</script>
</head>
<body>
<div>
<input type="text" id="textInput" />
<input type="button" value="Find Account ID" onclick="findAccountID();" />
</div>
</body>
</html>
函数findAccountID(){
var text=document.getElementById('textInput');
var value=encodeURIComponent(text.value);//编码特殊字符
location.href='**href此处路径**'+value;//转到URL
}
您可能需要在location.href&value之间添加斜杠/
在下面的代码段中,newHref
变量是
location.href
&文本框值。如果您打算导航到新的url,请设置location.href
到此newHref
函数findAccountID(){
var text=document.getElementById('textInput');
var value=encodeURIComponent(text.value);//编码特殊字符
让newHref=location.href+'/'+值
console.log(newHref)
}