質問

I've recently got the tag-it jquery successfull working on my site, there is a text area for the users to put in their own tagss, then a textarea, ie.

[ dog ] [ park ] [ weekend ]

Taking the dog to the park this weekend with Bill!

[Post]

I've been trying to google search this for hours with no results, so I am wondering if anyone on here has been able to tweak with the code, or you know of somewhere you could link me to, so that the user only needs to fill in the text area..

Taking the dog to the park this weekend with Bill!

Then on submission it generates tag words off the text area, with inclusions such as..

var tags = $('#message').val().split(' '); 
var excludeWords = ['took','the','a','to']; 
tags.filter(function (element, index, array) 
{ return ($.inArray(element, excludeWords) === -1); });
役に立ちましたか?

解決

Working Demo 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帰属
所属していません StackOverflow
scroll top