我想在数据库中从右到左记录信息,反之亦然
this.init = function() {
var pickListHtml =
"<div class='row'>" +
" <div class='col-sm-5'>" +
" <h1>Atanmamis Kullanicilar</h1>" +
" <select class='form-control pickListSelect pickData' multiple><option data-id='2'>aziz</option></select>" +
" </div>" +
" <div class='col-sm-2 pickListButtons'>" +
" <button type='button' class='pAdd btn btn-primary btn-sm'>" + opts.add + "</button>" +
" <button type='button' class='pAddAll btn btn-primary btn-sm'>" + opts.remove + "</button>" +
" <button type='button' class='pRemove btn btn-primary btn-sm'>" + opts.addAll + "</button>" +
" <button type='button' class='pRemoveAll btn btn-primary btn-sm'>" + opts.removeAll + "</button>" +
" </div>" +
" <div class='col-sm-5'>" +
" <h4>'Atanmis Kullanicilar'</h4>" +
" <select onchange='tester()' class='form-control pickListSelect pickListResult' id='pickListResult' multiple><option
data - id = '22' > kartas < /option></select > " +
" </div>" +
"</div>";
this.html(pickListHtml);
我正在添加jQuery但是如何编写一个方法来改变它?
function tester() {
select = $('#pickListResult');
selected = new Array();
////////i have no idea
alert(selected);
}
它有点不清楚你想要你的selected
包含什么,但你可以这样做。
function tester(obj) {
var select = $(obj); // select is now equal to the select your changed.
selected = select.find(":selected").toArray() // will return the options you have selected
console.log(selected);
}
这将返回您在选择中选择的元素
注意让它工作你的onchange
需要this
像onchange='tester(this)'
演示
function tester(obj) {
var select = $(obj);
var selected = select.find(":selected").toArray()
console.log(selected);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select onchange='tester(this)' class='form-control pickListSelect pickListResult' multiple>
<option>test1</option>
<option>test2</option>
<option>test3</option>
<option>test4</option>
</select>