如果输入val=,请转到URL
Go to URL if input val == something
所以,我找到了这个JSFiddle示例。在JSFiddle中运行良好,问题是,即使我搜索任何!=从"advogados"(只是测试),浏览器转到:http://www.site.com/index.html?procura=teste
没有jQuery冲突,没有html问题。
这是JS
$("#procura").on("submit", function(event){
// prevent form from being truely submitted
event.preventDefault();
// get value of text box
name = $("#procura_texto").val();
// compare lower case, as you don't know what they will enter into the field.
if (name.toLowerCase() == "advogados")
{
//redirect the user..
window.location.href = "http://jornalexemplo.com.br/lista%20online/advogados.html";
}
else
{
alert("no redirect..(entered: " + name + ")");
}
});
如果您的javascript在<form>
之前位于HTML中的某个位置,则$("#procura")
将是一个空集,因此提交操作不会绑定到任何内容。尝试以下代码:
<html>
<head>
<script type="text/javascript" src="/path/to/your/jquery.js"></script>
<script type="text/javascript">
$(function() {
// This code will be run if your document is completely
// parsed by the browser, thus all below elements are
// accessible
$('#procura').on('submit', ....);
});
</script>
</head>
<body>
<form id="procura">...</form>
</body>
</html>
$(function() {})
也称为$(document).ready(function() {})
,(文档)
您没有定义变量名。http://jsfiddle.net/zwbRa/59/
var name = $("#procura_texto").val();
相关文章:
- 需要URL模板占位符查找和替换功能的输入
- 如何存储&读取输入字段中的任意url
- 替换“;var url”;使用文本框输入
- 在Jquery中将鼠标悬停在图像上后获取输入标记的URL
- 如果输入val=,请转到URL
- 如果未输入URL,则隐藏按钮
- 将输入id传递到jquery ui自动完成中的url
- 验证多个URL输入字段
- 表单输入和选择值将创建一个URL
- I'm试图创建一个html表单,根据字段的输入生成url地址
- 如何从输入到url的路径创建html文件
- Regex来验证texarea输入,该输入必须是用新行分隔的URL
- Chrome webRequest只侦听用户输入的URL
- 如何识别用户在评论框中输入的URL
- 提交的表单重定向到输入URL
- 如何检查“http://”是否包含在 Angular .js 应用程序的 url 输入中
- Javascript或JQuery,用于在URL输入文本框时显示图像
- HTML5 URL输入元素的URL模式或REGEX
- 为从特定URL输入的用户更改页面元素
- 根据URL输入动态更改文本