我正在使用表情符号。我只想在设置为空后设置textarea的值。但它没有用。 我的代码在这里,
public class ApplicationProducts {
private final List<Product> myAppProducts = Collections.synchronizedList(new ArrayList<>());
private String firstPositionProductName;
private int firstPositionProductAvailability;
public void updateProducts(List<Product> products) {
myAppProducts.addAll(products);
}
public boolean checkAndReplaceFirstProduct(Product product) {
synchronized(myAppProducts) {
if((product.getId()).equals(myAppProducts.get(0).getId())) {
//calculations goes here to derive the below details
firstPositionProductAVailability = 10;
firstPositionProductName = abc;
return true;
} else {
return false;
}
}
}
public boolean removeFirstProduct(Product product) {
synchronized(myAppProducts) {
if((product.getId()).equals(myAppProducts.get(0).getId()) &(firstPositionProductName.getId().equals(myAppProducts.get(0).getId())) {
myAppProducts.remove(0);
return true;
} else {
throw new IllegalStateException(" Lock taken by some other product : product can't be removed ");
}
}
}
}
答案 0 :(得分:3)
使用val()
而不是text()
,html()
或empty()
来清除textarea
的价值:
$('#textarea').val('');
同样,使用它来设置值,而不是append()
:
$('#textarea').val(dataTextArea + dataCode + ' ');
您的#text
元素也是如此 - 假设它是input
或textarea
。您的代码的简化版本将是:
$('.tooltiptext .emoticon').click(function() {
$in = $(this);
setTimeout(function() {
$('#text').val(function(i, v) {
return v + $.emoticons.replace($in.html());
});
$('#textarea').val(function(i, v) {
return v + $in.context.innerText + ' ';
});
}, 100);
});