Textext.js - 删除所有标签并清理文本区域
Textext.js - Remove all tags and clean textarea
我有一个问题,我正在使用 Textext.js 从数据库中列出用户,我正在使用带有自定义数据对象的标签 ({name: 'nameTag', id: 1})问题是我需要用 "cleanFields" 按钮清理文本字段和标签,但我找不到办法做到这一点。这是我的代码:
$("#myTextarea").textext({
plugins: 'tags prompt autocomplete',
prompt: 'Add one...',
ext: {
itemManager: {
items: [],
stringToItem: function (str) {
for (var i = 0; i < this.items.length; i++)
if (this.items[i].name == str) {
id = this.items[i].id;
break;
}
return { name: str, id: id }; //tags with custom data objects
},
itemToString: function (item) {
this.items.push(item);
return item.name;
},
compareItems: function (item1, item2) {
return item1.name == item2.name;
}
}
}
})
.bind('getSuggestions', function (e, data) {
var list = f_GetListTags() //this returns the list from the database
, textext = $(e.target).textext()[0],
query = (data ? data.query : '') || '';
$(this).trigger(
'setSuggestions',
{ result: textext.itemManager().filter(list, query) }
);
})
按钮:
$("#cleanFields").click(function () {
$('#myTextarea').val(''); //this cleans the text area
//but i also need to remove all tags :(
});
请帮帮我! :(
标签存储在 div class .text-tags 中,并且它们有一个锚点 a.text -remove,你可以用来删除它们 - 如果你使用它,你不需要清除文本区域,因为它已经是删除的一部分:
$("#cleanFields").click(function () {
// This will clear the text area and remove the tags :)
$(".text-tags a.text-remove").trigger("click");
});
注意:这将清除所有带有标签的文本区域。除非您只使用 1 个标签输入字段,否则您应该考虑使您的选择器 (ids / classes) 更具体以避免冲突。
我有一个问题,我正在使用 Textext.js 从数据库中列出用户,我正在使用带有自定义数据对象的标签 ({name: 'nameTag', id: 1})问题是我需要用 "cleanFields" 按钮清理文本字段和标签,但我找不到办法做到这一点。这是我的代码:
$("#myTextarea").textext({
plugins: 'tags prompt autocomplete',
prompt: 'Add one...',
ext: {
itemManager: {
items: [],
stringToItem: function (str) {
for (var i = 0; i < this.items.length; i++)
if (this.items[i].name == str) {
id = this.items[i].id;
break;
}
return { name: str, id: id }; //tags with custom data objects
},
itemToString: function (item) {
this.items.push(item);
return item.name;
},
compareItems: function (item1, item2) {
return item1.name == item2.name;
}
}
}
})
.bind('getSuggestions', function (e, data) {
var list = f_GetListTags() //this returns the list from the database
, textext = $(e.target).textext()[0],
query = (data ? data.query : '') || '';
$(this).trigger(
'setSuggestions',
{ result: textext.itemManager().filter(list, query) }
);
})
按钮:
$("#cleanFields").click(function () {
$('#myTextarea').val(''); //this cleans the text area
//but i also need to remove all tags :(
});
请帮帮我! :(
标签存储在 div class .text-tags 中,并且它们有一个锚点 a.text -remove,你可以用来删除它们 - 如果你使用它,你不需要清除文本区域,因为它已经是删除的一部分:
$("#cleanFields").click(function () {
// This will clear the text area and remove the tags :)
$(".text-tags a.text-remove").trigger("click");
});
注意:这将清除所有带有标签的文本区域。除非您只使用 1 个标签输入字段,否则您应该考虑使您的选择器 (ids / classes) 更具体以避免冲突。