gpt4 book ai didi

javascript - 如何获取多选下拉框的值

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:20:51 25 4
gpt4 key购买 nike

如何获取这个多选下拉框的值?我不知道如何获得这些值。请帮忙解决这个问题。谢谢!

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/harvesthq/chosen/gh-pages/chosen.jquery.min.js"></script>
<link href="https://cdn.rawgit.com/harvesthq/chosen/gh-pages/chosen.min.css" rel="stylesheet"/>
</head>
<body>
<select data-placeholder="Begin typing a name to filter..." multiple class="chosen-select" name="test" id="test">
<option value=""></option>
<option>American Black Bear</option>
<option>Asiatic Black Bear</option>
<option>Brown Bear</option>
<option>Giant Panda</option>
<option>Sloth Bear</option>
<option>Sun Bear</option>
<option>Polar Bear</option>
<option>Spectacled Bear</option>
</select>
<input type="text" name="getvalue" id="getvalue">
<input type="button" onclick="a()" value="Submit">
<script>
$(".chosen-select").chosen({
no_results_text: "Oops, nothing found!"
});

function a() {
var value = document.getElementById('test').value;
document.getElementById('getvalue').value = value;
}
</script>

最佳答案

试试这个:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/harvesthq/chosen/gh-pages/chosen.jquery.min.js"></script>
<link href="https://cdn.rawgit.com/harvesthq/chosen/gh-pages/chosen.min.css" rel="stylesheet"/>
</head>
<body>
<select data-placeholder="Begin typing a name to filter..." multiple class="chosen-select" name="test" id="test">
<option value=""></option>
<option>American Black Bear</option>
<option>Asiatic Black Bear</option>
<option>Brown Bear</option>
<option>Giant Panda</option>
<option>Sloth Bear</option>
<option>Sun Bear</option>
<option>Polar Bear</option>
<option>Spectacled Bear</option>
</select>
<input type="text" name="getvalue" id="getvalue">
<input type="button" onclick="a()" value="Submit">
<script>
$(".chosen-select").chosen({
no_results_text: "Oops, nothing found!"
});

function a() {
var value = $('#test').val();
$('#getvalue').val(value);
}
</script>

关于javascript - 如何获取多选下拉框的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49568136/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com