jQuery从文本输入导航到页面(.htm)
这就是我想做的: 我在网站上有一些页面(离线演示) 当您在输入字段中键入“联系人”并单击“提交”时,我需要 转到contact.htm 我发现了类似的东西(学分) jQuery:jQuery从文本输入导航到页面(.htm),jquery,input,goto,Jquery,Input,Goto,这就是我想做的: 我在网站上有一些页面(离线演示) 当您在输入字段中键入“联系人”并单击“提交”时,我需要 转到contact.htm 我发现了类似的东西(学分) jQuery: jQuery(function() { $(document).ready(function() { function goTo() { window.location = where.value + '.htm'; return false;
jQuery(function() {
$(document).ready(function() {
function goTo() {
window.location = where.value + '.htm';
return false;
}
});
html:
我的问题是;提交输入后,此代码根本无法导航
这样做对吗<代码>window.location=where.value+'.htm'代码>'where'没有任何意义 给你的输入字段一个id 然后通过调用以下命令获取值:-
$('#where').val()
(假设给元素一个idwhere)“where”没有任何意义 给你的输入字段一个id 然后通过调用以下命令获取值:-
$('#where').val()
(假设您给元素的id为,其中)将HTML更改为此->
<form action="" method="post" onsubmit="return goTo()">
<input type="text" id="where" name="where" value="looking for" //added id attribute
onfocus="if(this.value == this.defaultValue) this.value = '';"
onblur="if(this.value == '') this.value = this.defaultValue;">
<input type="submit" value="Go">
</form>
将您的HTML更改为此->
<form action="" method="post" onsubmit="return goTo()">
<input type="text" id="where" name="where" value="looking for" //added id attribute
onfocus="if(this.value == this.defaultValue) this.value = '';"
onblur="if(this.value == '') this.value = this.defaultValue;">
<input type="submit" value="Go">
</form>
当然,这是有道理的。jQuery如何识别它是关于htm页面的?当然,这是有道理的。jQuery如何识别它是关于htm页面的?