引入以下文件
<!--必要样式--> <link rel="stylesheet" href="css/pickout.css"> <script src="js/pickout.js"></script>
Html
<select name="city" id="city" class="city pickout" placeholder="选择一个城市"> <option data-icon="♠" value="bj">北京</option> <option data-icon="♣" value="sh">上海</option> <option data-icon="♥" value="gz">广州</option> <option selected data-icon="♦" value="sz">深圳</option> <option data-icon="☺" value="xg">香港</option> <option data-icon="♀" value="sjz">石家庄</option> <option data-icon="♂" value="cd">成都</option> </select>
js
<script> // Preparar o select //pickout.to('.pickout'); pickout.to({ el:'.city', theme: 'dark', search: true }); // Caso o valor já venha do servidor, já atribui a sele??o automaticamente pickout.updated('.city'); </script>
$("#city").val();
IOS取不到值的话可以用
var t = $(".pk-field").html(); var option = $("#city option"); for (var i = 0; i < option.length; i++) { if (t == option[i].text) { value = option[i].value; break; } }
来获取
改下载的源码,可能不对但可以参考下:
在js中 createOption 函数里面// Event listener
item.addEventListener('click', function(e) { e.preventDefault(); e.stopPropagation(); // Converting to array, because it is a (object) HTMLCollection [].slice.call(select.children).map(function(item, index) { if (index === data.index) { item.setAttribute('selected', 'selected'); $(select).trigger("change"); //主动触发onchange事件 return; } item.removeAttribute('selected'); }); feedInput(select, txt.innerHTML); closeModal(); }, false);