我正在尝试在textarea /输入框中放置一些选定的人名,如果我取消选择该人,则每个人名都将对应一个按钮 应该从列表中删除
我想要这样
码
<button onclick="myFunction()">Try it</button>
<textarea id="t"></textarea>
<p id="demo"></p>
<script>
function myFunction() {
var str = "xyz abc abcd";
var res = str.split(" ");
document.getElementById("t").value = res;
}
</script>
答案 0 :(得分:0)
试试这个:
$("select").select2({
placeholder: "Select a state",
allowClear: true
});
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" />
<script
src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha256-k2WSCIexGzOj3Euiig+TlR8gA0EmPjuc79OEeY5L45g="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.min.js"></script>
<select multiple style="width:500px;">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
示例:
https://select2.github.io/examples.html