如何使用标签 [英] How to use tag-it
问题描述
我正在使用来自的tagit库 此处 我创建了可正常工作的tagit,并按如下所示创建了数组:
I am using tagit library from here I created the tagit which working correctly and i created the array as follows:
$("#name).tagit({
itemName: "teamId",
fieldName: "teamName",
availableTags: array,
allowSpaces:true,
caseSensitive:false,
removeConfirmation:true,
placeholderText:"Tag Group..."
});
var a =["1","2","3","4"];
在使用标签时,可以正确选择所有选项....我希望标签"4"必须作为默认选择出现,然后再选择任何选项.
while using the tag-it all options can be selected correctly ....I want that the tag "4" has to appear as default selection before choosing any option how can i do this..
其他信息:
源代码中有一个选项可用于创建新标签
there is a option available in the source to create the new tag
$("#myTags").tagit("createTag", "my-tag");
它对我也不起作用....
It is also not working for me....
推荐答案
如果我理解您的问题,可能有一些JavaScript错误可能会阻止您看到期望的结果.
If I understand your problem, there are a couple of javascript errors that may be preventing you from seeing what you expect to see.
-
Define the array before using it
.其次,引用的数组名为"array
",而定义的数组为"a
". -
"#name
->缺少右引号.
尝试在 -
$("#myTags").tagit("createTag", "my-tag");
在ul
的id
为'name'
之前不起作用.
myTags
上使用createTag
时,Define the array before using it
. Secondly, array referred to is named as 'array
' while the array defined is 'a
'."#name
--> This is missing the closing quote.$("#myTags").tagit("createTag", "my-tag");
is not working before theid
of yourul
is'name'
while you are trying to usecreateTag
onmyTags
.
对于第一个问题,您可以使用以下其中一个:
For your first problem, you can use one of these:
(1和2可能没有充分利用tagit库的潜力.)
(1 and 2 may not be fully utilizing the potential of tagit library.)
1)已经使用元素"4
"初始化了列表.诸如此类的html
1) Already initialize your list with an element '4
'. Something like this in your html :
<ul id="name">
<li>4</li>
</ul>
2).已在html中创建元素"4".
2) Create the element '4' already in your html.
var array = ["1", "2", "3", "4"];
$('#name').append('<li>' + array[3] +'</li>');
3) Use the createTag : $("#name").tagit("createTag", "4");
使用所有选项的完整工作示例:
Complete working example, with all the options used:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/tag-it.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#myTags").tagit();
var array = ["1", "2", "3", "4"];
$('#name').append('<li>' + array[3] +'</li>'); //Using Option 2
$("#name").tagit({
itemName: "teamId",
fieldName: "teamName",
availableTags: array,
allowSpaces:true,
caseSensitive:false,
removeConfirmation:true,
placeholderText:"Tag Group..."
});
$("#name").tagit("createTag", "NewTag"); //Using option 3
});
</script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/flick/jquery-ui.css">
<link href="css/jquery.tagit.css" rel="stylesheet" type="text/css">
</head>
<body>
<ul id="name">
<li>0</li> <!-- Using option 1 -->
</ul>
</body>
</html>
这篇关于如何使用标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!