對於下面的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來收集該值,然後重新定向而不刷新。