为什么我的表格没有在这个表格上被调用?

2024-09-30 12:32:33 发布

您现在位置:Python中文网/ 问答频道 /正文

使用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");
        } 
    }

当我点击我的按钮时,它除了处理“action”部分之外什么都不做,但是当我点击按钮时,它应该会发出警报,而不会在文本框中输入任何内容(或者为chrisFunction输入1或2)


Tags: textnamebrforminputreturniftype

热门问题