为js html提交输入与textarea的按钮

时间:2016-03-05 08:59:19

标签: javascript html meteor

2个问题:

  1. 当我在键盘上点击“enter”时,提交正常。但是,提交按钮本身不起作用。
  2. 如果我希望将整个<form>更改为<textarea>表单,我该如何调整代码?我试图改变这个事件,但形式并没有发生。
  3. 事件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> 
    

1 个答案:

答案 0 :(得分:0)

onConfigurationChanged标记没有类型属性 - 您可以将其设为<a>并根据自己的喜好设置样式,或者在<input type="submit">标记上添加点击监听器,但最好练习将是前者