我正在嘗試爲搜索框創建一個彈出框,並使用表單提交關鍵字 。我在網上瀏覽類似的問題,但我申請的唯一解決方案是刪除表單的提交元素 。它也沒有解決。有任何想法嗎?無法觸發從javascript提交
在django上工作,我可以提供更多的細節。
我的javascript的某些部分看起來是這樣的:
$("#dialog-form").dialog({
autoOpen: false,
height: 200,
width: 200,
modal: true,
buttons: {
"Search": function() {
var bValid = true;
allFields.removeClass("ui-state-error");
bValid = bValid && checkLength(keyword, "username", 2, 16);
bValid = bValid && checkRegexp(keyword, /^[a-z]([0-9a-z_])+$/i, "Keyword may consist of a-z, 0-9, underscores, begin with a letter.");
if (bValid) {
document.getElementById('searchForm_1_keyword').value = keyword.val();
document.getElementById('searchForm').submit(); //if I comment out this line it continues the next line, if not, it does not execute the next line
$("#testDiv").append("<tr>" +
"<td>" + keyword.val() + "</td>" +
"</tr>");
alert(keyword.val());
$(this).dialog("close");
}
},
Cancel: function() {
$(this).dialog("close");
}
},
close: function() {
allFields.val("").removeClass("ui-state-error");
}
});
和HTML看起來像這樣:
<div class="searchBox">
<form id='searchForm' method="POST" action="/dasdasasdas/" >{% csrf_token %}
<input type="text" name="column_name" value='supplier_name'>
<input type="text" name="keyword" id="searchForm_1_keyword" value=""/>
</form>
</div>
,這些都是我的jquery文件:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.8.18/jquery-ui.min.js" type="text/javascript"></script>
找到了解決辦法!
我犯了一個菜鳥的錯誤。我嵌套了表格。當我糾正這個錯誤時,它確實起作用。
你使用哪個瀏覽器? – Topera 2012-04-03 14:30:25