0
我想用批註拒絕批量記錄。當用戶點擊頁面上的拒絕按鈕時,我使用'textarea'標籤來獲取用戶的評論。jquery val函數從textarea獲取舊值
問題是當我鍵入一些備註並在提示中單擊確定按鈕時,我無法獲得註釋textarea的值。該值爲空。當我關閉提示並再次執行此過程時,我會在輸入之前得到textarea的值。 jquery代碼寫在HtmlHelper類文件中。
這裏是jQuery函數:
$('#{0}BulkRejection').click(function() {{
var selectedRowId = $('#{0}').jqGrid('getGridParam', 'selarrrow');
for (var i = 0; i < selectedRowId.length; i++) {{
cellValue = $('#{0}').jqGrid('getCell', selectedRowId[i], '{3}');
var ch = jQuery('#{0}').find('#'+selectedRowId[i]+' input[type=checkbox]').prop('checked');
if(ch)
{{
stringArray[i + 1] = cellValue;
}}
}}
if (stringArray.length == 0) {{
alert('No Record Selected');
return false;
}}
var execute = function() {{
alert($('#AuthRemarks').find('textarea.form-control').val() + '-' +$('#AuthRemarks').val())
if ($('#AuthRemarks').val() == '') {{
alert('Enter the Reject Remarks');
$('#AuthRemarks').focus();
}}
else {{
$(this).dialog('close')
stringArray[0] = $('#AuthRemarks').val();
var postData = {{ values: stringArray }};
$.ajax({{
type: 'POST',
url: RootUrlName+'/{5}',
data: postData,
success: function (data) {{
alert(data.Result);
}},
dataType: 'json',
traditional: true
}});
$('<div title=""Confirm Box""></div>').dialog({{
open: function() {{
$(this).html('<font color=""Green"">Record(s) Rejected Successfully</font>');
}},
close: function() {{
$(this).remove();
window.location.href = RootUrlName+'/{2}'
}},
resizable: false,
height: 170,
modal: true,
buttons: {{
'Ok': function() {{
$(this).dialog('close');
window.location.href = RootUrlName+'/{2}'
}}
}}
}});
}}
}}
var cancel = function() {{
$(this).dialog('close')
}}
var dialogOpts = {{
buttons: {{
'Ok': execute,
'Cancel': cancel
}}
}};
if (confirm('Are you sure to reject this record(s)?')) {{
$('#dialog').dialog(dialogOpts);
}}
}});
}});
HTML代碼:
<div class='panel-body'>
<div id='dialog' ' title='Reject Remarks' style='display: none'>
<textarea class='form-control' rows='5' id='AuthRemarks'
maxlength='250' ></textarea>
</div>
</div>
所以它表明,即使我進入拒絕的話,然後點擊確定按鈕,在「輸入拒絕備註」的消息,由於字段「AuthRemarks」值爲空(請參閱下面的給定行)。它不是第一次工作。
if ($('#AuthRemarks').val() == '') {{
alert('Enter the Reject Remarks');
$('#AuthRemarks').focus();
}}
您確定自己的頁面上沒有另外一個id爲AuthRemarks的元素嗎? – JB06
我相信,沒有其他元素的id爲AuthRemarks。 –