对于下面的HTML检索输入文本值
<form>
Enter hash here: <input type="text" name="hash">
<button type="submit" formaction="/tasks/">Retrieve Url</button>
</form>
我怎样才能重新将用户引导到/tasks/A
其中A
=无论用户在“哈希” <input>
框中键入?
感谢
对于下面的HTML检索输入文本值
<form>
Enter hash here: <input type="text" name="hash">
<button type="submit" formaction="/tasks/">Retrieve Url</button>
</form>
我怎样才能重新将用户引导到/tasks/A
其中A
=无论用户在“哈希” <input>
框中键入?
感谢
看看this post会有所帮助。
它和你想要的例子完全一样。
你需要或者防止提交的默认操作(event.preventDefault();
),或更改按钮从type="submit"
到type="button"
,然后使用JavaScript来设置窗体的动作。下面是一些jQuery的是能为你做的工作:
$('button').click(function() {
//set the form action
$('form').attr('action', '/tasks/'+$('input[type="text"]').val())
//submit the form
.submit();
});
见工作例如,你可以使用一个临时职位和重定向。例如:
<?php
if(isset($_POST['hash'])){
header("Location:/tasks/" . $_POST['hash']);
}
?>
或者,如果您希望可以使用AJAX来收集该值,然后重新定向而不刷新。