0

HTML 代码:

  <!-- Modal -->
  <div class="modal fade" id="myModal">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">Book return comment (optional):</h4>
        </div>
        <div class="modal-body">
           <textarea id="comment" class="form-control" rows="6" maxlength="500" placeholder="Please limit your comment to 500 characters."></textarea>
        </div>
        <div class="modal-footer">
          <a href="#" id="btn-confirm" class="btn">Confirm</a>
          <a href="#" class="btn">Cancel</a>
        </div>
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->
  <div id="commentField">
  </div>

JS:

function getComment () {
var comment = $('#comment').val();
$('#commnetField').html(comment);
}

$('#btn-confirm').click(function() {
});

我是 jQuery 的新手,这段代码有什么问题?我想获取 textarea 文本并将其显示在 id='commentField' 的 div 中。

4

2 回答 2

2

您的 JS 中有错字(#commnetField而不是#commentField)。您究竟想通过单击按钮实现什么?目前你什么都不做。

function getComment () {
  var comment = $('#comment').val();
  $('#commentField').html(comment);
}

$('#btn-confirm').click(function() { });

如果要在按钮单击上设置文本框,则必须将其更改为。

$('#btn-confirm').click(getComment);
于 2013-08-05T14:38:35.983 回答
0

我猜你只是弄错了。您已将“空”函数设置为#btn-confirm 的“单击”事件处理程序。应该有你 getComment 功能,例如

$('#btn-confirm').on('click', getComment)
于 2013-08-05T14:43:36.893 回答