我想要有幾個不同的選項可以映射到不同的動作,但我只需要一個提交按鈕。我不能爲我的生活得到這個工作。這裏是我到目前爲止的代碼:根據用戶填寫的字段動態設置表單動作
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel=stylesheet type=text/css href="{{ url_for('static', filename='css/main.css') }}">
<meta charset="UTF-8">
</head>
<body>
<script type=text/javascript>
function clicked() {
document.getElementById('id').action = "/query";
document.getElementById('filename').action = "/fname";
document.getElementById('dep').action = "/dependency";
return true;
}
</script>
<div id="header">
<h1>TestPy</h1>
</div>
<hr>
<div id="wrapper">
<div class="query-menu" id="nav">
<form name="query_form" id="query" onsubmit="clicked()" method=post>
<fieldset class="fieldset-auto-width">
<legend>Query</legend>
<table style="width:25%">
<tr>
<td>Plugin ID:</td>
<td><input type=text name=script_id id="id" placeholder="19506"></td>
</tr>
<tr>
<td>Filename Search:</td>
<td><input type=text name=filename id="fname" placeholder="test.file"></td>
</tr>
<tr>
<td>Dependency:</td>
<td><input type=text name=dep id="dep" placeholder="dependency"></td>
</tr>
<tr>
<th rowspan="2"><td><input type=submit value=Query class="btn"></td></th>
</tr>
</table>
</fieldset>
</form>
</div>
<div class="content" id="section">
{% block body %}{% endblock %}
</div>
</div>
</body>
</html>
我想要做的是有這三個表單字段每個地圖回一個單獨的網址,但我不能得到這個工作。如果我將JavaScript取出並將網址硬編碼,那麼它工作正常。 HTML/JavaScript並不是我的強大語言,所以我很欣賞任何可以提供的反饋。謝謝!
那麼你如何決定要調用哪個動作? – Roshan
你怎麼沒有javascript? –