Html y使用较旧的引导版本(2.3.2和3),并且没有正确维护,除非您对源代码进行大量编辑,否则很可能不会在较新的版本中运行。在此处找到了更好的解决方案:。您能解释一下您是如何使此答案对未来的读者更有用的吗? <div id="master_div">
Html y使用较旧的引导版本(2.3.2和3),并且没有正确维护,除非您对源代码进行大量编辑,否则很可能不会在较新的版本中运行。在此处找到了更好的解决方案:。您能解释一下您是如何使此答案对未来的读者更有用的吗? <div id="master_div">,html,input,tags,Html,Input,Tags,y使用较旧的引导版本(2.3.2和3),并且没有正确维护,除非您对源代码进行大量编辑,否则很可能不会在较新的版本中运行。在此处找到了更好的解决方案:。您能解释一下您是如何使此答案对未来的读者更有用的吗? <div id="master_div"> <div id="categories"> </div> <div id="input"> <input type="text" value="" />
y使用较旧的引导版本(2.3.2和3),并且没有正确维护,除非您对源代码进行大量编辑,否则很可能不会在较新的版本中运行。在此处找到了更好的解决方案:。您能解释一下您是如何使此答案对未来的读者更有用的吗?
<div id="master_div">
<div id="categories">
</div>
<div id="input">
<input type="text" value="" />
</div>
</div>
<input type="text" value="html,input,tag" data-role="tagsinput"></input>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="http://bootstrap-tagsinput.github.io/bootstrap-tagsinput/dist/bootstrap-tagsinput.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="http://bootstrap-tagsinput.github.io/bootstrap-tagsinput/dist/bootstrap-tagsinput.min.js"></script>
const AutoList=()=>{
const [currentTagText, setCurrentTagText] = useState("");
const [tags, setTags] = useState(["javascript"]);
const handleTag = (e) => {
setCurrentTagText(e.target.value);
if (e.keyCode == 13 && currentTagText) {
setTags((prevTags) => [...prevTags, currentTagText]);
setCurrentTagText("");
} else if (e.keyCode == 32 && currentTagText) {
setTags((prevTags) => [...prevTags, currentTagText]);
setCurrentTagText("");
}
};
const removeTag = (index) => {
const newTagArray = tags;
newTagArray.splice(index, 1);
setTags([...newTagArray]);
};
return (
<div className="masterStackDiv">
<div
className="stackTags"
style={{ display: tags.length > 0 ? "flex" : "none" }}
>
{tags.map((tag) => {
return (
<div className="stackTag">
<button
onClick={() => removeTag(index)}
className="tagCloseBtn"
>
x
</button>
#{tag}
</div>
)
})}
</div>
<div className="stackInput">
<input
type="text"
onKeyDown={handleTag}
onChange={handleTag}
value={currentTagText}
/>
</div>
</div>
)
}
.masterStackDiv {
width: auto;
background-color: transparent;
border: none;
display: flex;
align-items: center;
}
.stackInput input[type="text"] {
border: none;
background-color: transparent;
color: white;
font-family: "Segoe UI";
font-size: 0.8em;
float: right;
margin-left: 5px;
width: auto;
border-bottom: 2px solid white;
}
.stackTag {
background-color: #707070;
color: white;
height: 20px;
width: auto;
border-radius: 10px;
font-size: 0.7em;
padding: 5px;
margin: 3px;
display: flex;
align-items: center;
}
.stackTags {
display: flex;
justify-content: center;
align-items: center;
height: 30px;
width: auto;
}
.tagCloseBtn {
border: none;
background-color: transparent;
border-radius: 5px;
}
.tagCloseBtn:hover {
background-color: white;
cursor: pointer;
}