2016-03-05 81 views
0

2個問題:提交按鈕輸入文本區域相比爲JS HTML

  1. 提交作品時,我打「輸入」鍵盤上的。但是,提交按鈕本身不起作用。
  2. 如果我希望將整個<form>更改爲<textarea>表單,我應該如何調整代碼?我試圖改變事件,但形式並不火。

事件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> 

回答

0

<a>標籤沒有一個類型的屬性 - 你可以把一個<input type="submit">和風格如何,你像或者在標籤上放一個點擊監聽器,但最好的做法是b e前

+0

謝謝!愚蠢的疏忽對我而言 – Thinkerer