为什么我不能用这个按钮提交表格

时间:2017-05-05 05:39:15

标签: javascript validation web2py

我有一个web2py应用程序,我可以按“Enter”提交自定义表单但是当点击按钮时,我收到错误。这是代码;   这不起作用

<div class="message_input_wrapper">
    {{=form.custom.begin}}
    <input name="body" class="message_input" placeholder="Type your message here..."/>                
    {{=form.custom.end}}                
</div>
<button type="submit" class="send_message">Send</button>

这也不起作用:

<div class="message_input_wrapper">
    {{=form.custom.begin}}
    <input name="body" class="message_input" placeholder="Type your message here..."/>                
    {{=form.custom.end}}   
    <button type="submit" class="send_message">Send</button>             
</div>

这是js代码:

(function () {
var Message;
Message = function (arg) {
    this.text = arg.text, this.message_side = arg.message_side;
    this.draw = function (_this) {
        return function () {
            var $message;
            $message = $($('.message_template').clone().html());
            $message.addClass(_this.message_side).find('.text').html(_this.text);
            $('.messages').append($message);
            return setTimeout(function () {
                return $message.addClass('appeared');
            }, 0);
        };
    }(this);
    return this;
};
$(function () {
    var getMessageText, message_side, sendMessage;
    message_side = 'right';
    getMessageText = function () {
        var $message_input;
        $message_input = $('.message_input');
        return $message_input.val();
    };
    sendMessage = function (text) {
        var $messages, message;
        if (text.trim() === '') {
            return;
        }
        $('.message_input').val('');
        $messages = $('.messages');
        message_side = message_side === 'left' ? 'right' : 'left';
        message = new Message({
            text: text,
            message_side: message_side
        });
        message.draw();
        return $messages.animate({ scrollTop: $messages.prop('scrollHeight') }, 300);
    };
    $('.send_message').click(function (e) {
        return sendMessage(getMessageText());
    });
    $('.message_input').keyup(function (e) {
        if (e.which === 13) {
            return sendMessage(getMessageText());
        }
    });

1 个答案:

答案 0 :(得分:1)

{{=form.custom.end}}包含表单结束标记(即</form>)。由于提交按钮位于表单之外,因此不会提交表单。只需在提交按钮标记后移动{{=form.custom.end}}即可。