我需要有允許使用自由文本的多行文本框,但是如果我啓動輸入字符:「@@」
帶有可用標籤的自動填充框應顯示並允許我從現有標籤中選擇標籤,並且標籤名稱中不應出現「@@」字符。帶有強制文本和自由文本的自動完成標籤
目前我正在玩jQuery UI的tag-it plugin,但無法弄清楚如何允許自由文本和只shw自動填充框在「@@」輸入。以及如何使用textarea而不是常規輸入。
另外,我想迫使他們,如果他們進入@@,不允許輸入自由文本,從列表中選擇(第一個可用的選擇將是一件好事)
的Javascript:
$(document).ready(function() {
//The demo tag array
var availableTags = [
{value: 1, label: 'tag1'},
{value: 2, label: 'tag2'},
{value: 3, label: 'tag3'}];
//The text input
var input = $("input#text");
//The tagit list
var instance = $("<ul class=\"tags\"></ul>");
//Store the current tags
//Note: the tags here can be split by any of the trigger keys
// as tagit will split on the trigger keys anything passed
var currentTags = input.val();
//Hide the input and append tagit to the dom
input.hide().after(instance);
//Initialize tagit
instance.tagit({
tagSource:availableTags,
tagsChanged:function() {
//Get the tags
var tags = instance.tagit('tags');
var tagString = [];
//Pull out only value
for (var i in tags){
tagString.push(tags[i].value);
}
//Put the tags into the input, joint by a ','
input.val(tagString.join(','));
}
});
//Add pre-loaded tags to tagit
instance.tagit('add', currentTags);
});
HTML:
<p>This example shows how to use Tagit on an input!</p>
<input type="text" id="text" name="tags" value="one,two,three"/>
測試在這裏:http://jsfiddle.net/hailwood/u8zj5/
我覺得@ DUY-阮回答這裏的http://計算器。com/a/6393740/180100適合您的需要(只有區別是'@'而不是'@@')。 – 2012-11-19 06:44:23
@RC。,謝謝你的建議,但它不能按預期工作。 1.不作爲標籤樣式,因此無法通過單擊「x」來刪除標籤。 2.當我添加多個標籤時CSS無法按預期工作。 3.當我輸入「@」時,不顯示自動填充框,只有在輸入「@」+字母時才顯示框。 – user194076