我有两个同一类和不同身份的textarea。一次只启用一个。我需要使用ajax将启用的textarea值保存到数据库。但我不知道如何找到启用textarea的值。
这是我的代码:
$('#messageTransactionalUnicode').attr('disabled', 'true');
$('#save-template-transactional').click(function() {
$('#messageTransactionalError').text('');
if($('.messageTransactional').val() == ''){
$('#messageTransactionalError').text('required');
return false;
}
else {
var templateText = $('.messageTransactional').val();
//alert(templateText);
$.ajax({
url : base_url + 'SMS/SaveTemplate',
type : 'POST',
data : {templateText : templateText, type: 'transactional' },
success:function(data) {
if(data == 1){
notification('Template submitted successfully', 'success');
}
else{
notification('An error occured, please try again', 'failure');
}
console.log(data);
}
});
}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea class="messageTransactional" name="messageTransactional" id="messageTransactionalEnglish" placeholder="Enter your message here.." maxlength="160" ></textarea>
<textarea class="messageTransactional" name="messageTransactional" id="messageTransactionalUnicode" placeholder="Enter your message here.." style="display: none;" maxlength="70" ></textarea>
<button class="save-template" id="save-template-transactional" type="button">Save Template</button>
&#13;
我有一个下拉列表,在它的更改事件中,我可以禁用和启用这两个textarea,就像切换功能一样。该部分正在运行,但var templateText = $('.messageTransactional').val();
将始终显示第一个textarea值。
答案 0 :(得分:1)
public class XCell extends TableCell<TestApp.Person, String> {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if(empty){ // check if the cell contains an item or not, if it not you want an empty cell without text.
setText(null);
}else {
setText(item);
setStyle("-fx-font-weight: bold; -fx-alignment: center"); // You can do the styling here.
// Any further operations to this cell can be done here in else, since here you have the data displayed.
}
// Since as I see you don't have any graphics in the cell(like TextField, ComboBox,...) you
// don't have to take care about the graphic, but only the displaying of the text.
}
}
答案 1 :(得分:1)
使用以下内容在您的情况下使用:enabled
选择器获取enabled元素的值:
var templateText = $('.messageTransactional:enabled').val();