我有一个jquery模式,当用户点击页面上的拒绝按钮时显示用于获取用户评论。jquery从模态文本区获取旧值
问题是,当我键入一些评论,并确认模式中的拒绝按钮,我不能得到注释textarea的值。当我重新加载页面,并再次执行此过程时,在重新加载页面之前,我得到了textarea的值。
这里是jQuery函数:
$("#rejectBtnHOD").on('click', function(){
$("#modal-container-522009").modal(); // Displays modal well
});
$(document).on("click", "#confirmRejection", function(){
var vid = "<?php echo $fields['vid']; ?>"; // getting the request id well
var rejComment = $('body').find('#comment').val(); // cant get the value of textarea
alert(rejComment); return false;
});
HTML代码(模式):
<div class="modal fade" id="modal-container-522009" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
<h4 class="modal-title" id="myModalLabel">
Leave a comment!
</h4>
</div>
<div class="modal-body" style="height: 300px;">
<textarea id="comment" class="col-md-12" style="height: 200px;" ></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button id="confirmRejection" type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
顺便说一句,如果我有<input type="text">
更换<textarea>
标签,它工作得很好!
你的代码似乎工作,好吗[这个小提琴(http://jsfiddle.net/omuswtkp/) – shxfee 2014-10-02 10:32:03
是的,在小提琴,代码工作正常,如果我不是试图从页面获取他textarea的价值,而不是模态。 – goseo 2014-10-02 10:45:56