使用django atm:
以下是我的表格:
<form name="chrisForm" action="">
<input type="text" name="christext">
<br>
<button type='submit' class='btn btn-primary btn-xs' onclick="return chrisFunction()">
Submit</button>
</form>
<!-- modify the searchwords form -->
<form name="articleForm" action="" method="post">{% csrf_token %}
<input type="text" placeholder='Modify the keywords' name="searchkeyword">
<br><button type="submit" class="btn btn-success btn-xs" onclick="return validateForm()">Submit</button>
</form>
现在这里是外部来源的javascript函数:
function validateForm() {
var x = document.forms['articleForm']['searchkeyword'].value;
if (x == null || x == "") {
alert("Please enter a search keyword(s)");
return false
}
}
function chrisFunction() {
var y = (document.forms['chrisForm']['christext'].value);
if (y === "1" || y === "2") {
alert('You have entered 1 or 2, congrats!');
return false
}
else if
(y === "" || y === null) {
window.open('http://forbiddengrounds.net',"", height="200", width="200");
}
}
当我点击我的按钮时,它除了触发&#34;动作&#34;之外什么都不做。部分,但是当我单击按钮而不在文本框中放置任何内容(或者为chrisFunction输入1或2)时,它应该发出警告