Ara*_*han 2 jquery jquery-ui tag-it
我在这里使用tagit库 我创建了正确工作的tagit,我按如下方式创建了数组:
$("#name).tagit({
itemName: "teamId",
fieldName: "teamName",
availableTags: array,
allowSpaces:true,
caseSensitive:false,
removeConfirmation:true,
placeholderText:"Tag Group..."
});
var a =["1","2","3","4"];
Run Code Online (Sandbox Code Playgroud)
使用标签时 - 可以正确选择所有选项....我希望标签"4"在选择任何选项之前必须作为默认选择出现我该怎么做...
附加信息:
源中有一个选项可用于创建新标记
$("#myTags").tagit("createTag", "my-tag");
Run Code Online (Sandbox Code Playgroud)
它也不适合我....
如果我理解你的问题,有几个javascript错误可能会阻止你看到你期望看到的.
Define the array before using it.其次,引用的数组被命名为' array',而定义的数组是' a'."#name - >这是缺少结束语.$("#myTags").tagit("createTag", "my-tag");之前没有工作id你的ul就是'name'当你要使用createTag的myTags.对于您的第一个问题,您可以使用以下方法之一:
(1和2可能没有充分利用tagit库的潜力.)
1)已经使用元素' 4' 初始化列表.你的HTML中有这样的东西:
<ul id="name">
<li>4</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
2)在你的html中创建元素'4'.
var array = ["1", "2", "3", "4"];
$('#name').append('<li>' + array[3] +'</li>');
Run Code Online (Sandbox Code Playgroud)
3) Use the createTag : $("#name").tagit("createTag", "4");
完整的工作示例,使用了所有选项:
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6891 次 |
| 最近记录: |