我有一個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