本文介绍了如何获取多选下拉框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何获得这个多选下拉框的值?我不知道如何获得这些值.请帮忙解决这个问题.谢谢!
How i can get the value of this multiple choose dropdown box? I cant figure out how i can get the values. Please help on this. Thanks!
<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>
这篇关于如何获取多选下拉框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!