0

是的,我对 chrome/jquery mobile 有疑问。在 Internet Explorer 中,脚本似乎运行良好。

这是 jsfiddle示例

问题是当我在单击后从两个列表中选择多个项目时,它会很好。当我第二次这样做时,列表不再被清除。

HTML 代码:

    <!-- Select Multiple -->
<div class="control-group" style="float: left;">
  <label class="control-label" for="selectmultiple">Licentie Man</label>
  <div class="controls">
    <select id="maleLicense" style="height: 210px;" name="maleLicense" class="input-medium" multiple="multiple">
    <option value="l0000000000000000000100">Amateur</option>
    <option value="l0000000000000000000001">Basislid</option>
    <option value="l0000000000000000001000">Belofte</option>
    <option value="l0000000000000000010000">Elite</option>
    <option value="l0000000000000000100000">Jeugd</option>
    <option value="l0000000000000001000000">Junior 1e jaars</option>
    <option value="l0000000000000010000000">Junior 2e jaars</option>
    <option value="l0000000000000100000000">Nieuweling 1e jaars</option>
    <option value="l0000000000001000000000">Nieuweling 2e jaars</option>
    <option value="l0000000000100000000000">Professional-A</option>
    <option value="l0000000000010000000000">Professional-B</option>
    <option value="l0000000001000000000000">Sportklasse</option>
    </select>
  </div>
  </div>

<!-- Select Multiple -->
<div class="control-group">
  <label class="control-label" for="selectmultiple">Licentie Vrouw&nbsp;&nbsp;&nbsp;
</label>
  <div class="controls">
    <select id="femaleLicense" style="height: 210px;" name="femaleLicense" class="input-medium" multiple="multiple">
    <option value="l0000000010000000000000">Amateur</option>
    <option value="l0000000000000000000010">Basislid</option>
    <option value="l0000000100000000000000">Belofte</option>
    <option value="l0000001000000000000000">Elite</option>
    <option value="l0000010000000000000000">Jeugd</option>
    <option value="l0000100000000000000000">Junior 1e jaars</option>
    <option value="l0001000000000000000000">Junior 2e jaars</option>
    <option value="l0010000000000000000000">Nieuweling 1e jaars</option>
    <option value="l0100000000000000000000">Nieuweling 2e jaars</option>
    <option value="l1000000000000000000000">Professional-B</option>
    </select>
  </div>
</div>
<a id="click">empty input</a>

jQuery代码:

$(document).ready(function() {
$("a#click").click(function(){
    "use strict";
    $('#maleLicense').children(':selected').removeProp('selected');
    $('#femaleLicense').children(':selected').removeProp('selected');
});
});

一张图片以直观地显示我的意思: 在此处输入图像描述

4

3 回答 3

0

尝试.prop('selected', false)代替(http://api.jquery.com/prop/),我认为它工作正常

$(document).ready(function() {
  $("a#click").click(function(){
    $('#maleLicense').children(':selected').prop('selected', false);
    $('#femaleLicense').children(':selected').prop('selected', false);
  });
});

更新了 jsfiddle:http: //jsfiddle.net/7x9BT/3/

于 2013-07-22T16:46:51.827 回答
0

使用removeAttr如下:

$(document).ready(function() {
    $("a#click").click(function() {
        "use strict";
        $('#maleLicense option:selected').removeAttr('selected');
        $('#femaleLicense option:selected').removeAttr('selected');
    });
});

jsFiddle

于 2013-07-22T16:47:12.720 回答
0

而不是removeAttr,我使用$("#maleLicense").val(null);并且一切正常。

这是小提琴。 http://jsfiddle.net/7x9BT/5/

于 2013-07-22T16:52:13.523 回答