[英]Tag-it Textarea autogenerate
我最近在我的網站上成功運行了tag-it jquery,有一個文本區域供用戶放置自己的標簽,然后是文本區域,即。
[ dog ] [ park ] [ weekend ]
Taking the dog to the park this weekend with Bill!
[Post]
我一直在嘗試使用Google搜索此程序,但沒有結果,所以我想知道這里的任何人是否都可以調整代碼,或者您知道可以鏈接到我的地方,以便用戶只需要填寫文本區域。
Taking the dog to the park this weekend with Bill!
然后在提交時,它會在文本區域之外生成標記詞,並包含諸如。
var tags = $('#message').val().split(' ');
var excludeWords = ['took','the','a','to'];
tags.filter(function (element, index, array)
{ return ($.inArray(element, excludeWords) === -1); });
工作演示http://jsfiddle.net/cse_tushar/U94Le/
$('#b').click(function () {
tags = $('#message').val();
tags = tags.replace(/!/g, '');
var excludeWords = ['took', 'the', 'a', 'to', 'with', 'dog', 'this'];
$.each(excludeWords, function (i, v) {
pos = tags.indexOf(excludeWords[i]);
while (pos > -1) {
tags = tags.replace(" " + excludeWords[i] + " ", ' ');
pos = tags.indexOf(excludeWords[i], pos + 1);
}
});
console.log(tags);
tags = tags.split(' ');
console.log(tags);
$('#output').html('<pre>' + tags + '</pre>');
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.