真爱无限的知识驿站

学习积累技术经验,提升自身能力

[CodeSnippet]select2插件allowClear不生效解决方法

code:

//html
//The first option must be empty in order to get placeholder working!

<select id="belongingUserId" placeholder="请选择归属人">
  <option></option>
  <option>Option value</option>
</select>
//js
$(function () {
    $("#belongingUserId").select2({ allowClear: true});
});
//未选择时,取值时为空,取值时要判断
var belongingUserId = $('#belongingUserId').val();
if (belongingUserId == '') belongingUserId = '-1';//如果是空,赋默认值


<< 1 >>

Powered By Z-BlogPHP 1.7.3

Copyright 2024-2027 pukuimin Rights Reserved.
粤ICP备17100155号