[英]How to add a class to a tag in Select2
在 select2 中,當用戶通過createTag選項創建標簽時,我能夠驗證它。
如何將.text-danger
類的類添加到驗證失敗的標簽中? 例如:
$('#myselect').select2({
createTag: function(term, data) {
var value = term.term;
if (validateEmail(value)) {
return {
id: value,
text: value
};
}
return {
id: value,
text: value,
class: 'text-danger' <------ NEW CLASS
};
}
});
如果驗證失敗,您可以將類添加到目標元素示例#mySelect
:
$('#myselect').select2({
createTag: function(term, data) {
var value = term.term;
if (validateEmail(value)) {
return {
id: value,
text: value
};
}
$('#myselect').addClass('text-danger');
return {
id: value,
text: value
};
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.