Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 输入的提交按钮与js html的文本区域_Javascript_Html_Meteor - Fatal编程技术网

Javascript 输入的提交按钮与js html的文本区域

Javascript 输入的提交按钮与js html的文本区域,javascript,html,meteor,Javascript,Html,Meteor,2个问题: 当我在键盘上按“回车”键时,“提交”起作用。但是,“提交”按钮本身不起作用 如果我希望将整个更改为表单,我应该如何调整代码?我试图改变事件,但表单没有启动 事件js 'submit form': function(e, template) { e.preventDefault(); var $body = $(e.target).find('[name=body]'); var comment = { body: $body.val(),

2个问题:

  • 当我在键盘上按“回车”键时,“提交”起作用。但是,“提交”按钮本身不起作用
  • 如果我希望将整个
    更改为
    表单,我应该如何调整代码?我试图改变事件,但表单没有启动 事件js

      'submit form': function(e, template) {
        e.preventDefault();
        var $body = $(e.target).find('[name=body]');
    
        var comment = {
          body: $body.val(),
          postId: template.data._id
        };
    
        var errors = {};
        if (! comment.body) {
          errors.body = "Input and/or attach content?";
          return Session.set('commentSubmitErrors', errors);
        }
    
        Meteor.call('commentInsert', comment, function(error, commentId) {
          if (error){
            throwError(error.reason);
          } else {
            $body.val('');
          }
        });
    
    html文件

        <div class="page-content message-content">
            <form class="form-send-message" data-keyboard-attach >
            <!-- <form> -->
                <input name="body" id="body" type="text" placeholder="content">
                <a href="#" class="button" type="submit">comment</a> 
    
            <!-- <a href="#" class="link" type="submit">
                   <i class="icon ion-android-send"></i> 
                   picture icon doesnt work
                 </a> -->
    
            <!-- what I aim to have
    
             <textarea placeholder="add comment" name="body" id="body"></textarea>
            <a href="#" class="link" type="submit">
                <i class="icon ion-android-send"></i> --> 
    
            </form>
        </div> 
    
    
    
    一个
    标记没有类型属性-您可以将其设置为
    并按自己喜欢的方式设置样式,或者在
    标记上放置一个单击侦听器,但最佳做法是前者