📅  最后修改于: 2023-12-03 15:14:50.077000             🧑  作者: Mango
EasyUI jQuery tagbox Widget is a user-friendly tool that allows users to add and remove tags in a simple way. The widget is built using jQuery and is fully customizable.
npm install easyui-tagbox
yarn add easyui-tagbox
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="easyui-tagbox.css">
</head>
<body>
<!-- Your HTML code here -->
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="easyui-tagbox.min.js"></script>
</body>
</html>
To use the EasyUI jQuery tagbox Widget, simply add a div
element with an id
to your HTML code, and initialize the widget in your JavaScript code.
HTML:
<div id="tagbox"></div>
JavaScript:
$('#tagbox').tagbox();
The EasyUI jQuery tagbox Widget provides several options that can be used to customize the widget's behavior. Here are some of the available options:
prompt
Sets the text to display in the tagbox when it is empty.
Default: 'Add a tag'
$('#tagbox').tagbox({
prompt: 'Enter a new tag'
});
separator
Sets the character used to separate tags.
Default: ','
$('#tagbox').tagbox({
separator: ';'
});
width
Sets the width of the tagbox in pixels.
Default: 'auto'
$('#tagbox').tagbox({
width: 200
});
height
Sets the height of the tagbox in pixels.
Default: 'auto'
$('#tagbox').tagbox({
height: 100
});
limitToList
Enables or disables the ability to add tags that are not in the autocomplete list.
Default: true
$('#tagbox').tagbox({
limitToList: false
});
The EasyUI jQuery tagbox Widget provides several methods that can be used to manipulate the widget's behavior. Here are some of the available methods:
getTags()
Returns an array of the currently selected tags.
var tags = $('#tagbox').tagbox('getTags');
console.log(tags); // ['tag1', 'tag2', ...]
setTags(tags)
Sets the currently selected tags.
var tags = ['tag1', 'tag2', ...];
$('#tagbox').tagbox('setTags', tags);
select()
Selects the tagbox.
$('#tagbox').tagbox('select');
unselect()
Unselects the tagbox.
$('#tagbox').tagbox('unselect');
EasyUI jQuery tagbox Widget is released under the MIT license.