使用Onion和wewe的过滤器下拉列表正在工作但是当我更改为日期格式时,过滤器不起作用。我知道如何解决这个问题。
这是我的HTML代码
<div>
<select ID="DropDownList1" Height="72px" Width="184px">
<option Value="111/111">All</option>
<option Value="">2013-10-10</option>
<option Value="">2013-10-09</option>
<option Value="">Onion</option>
<option Value="">Wewe</option>
</select>
<br />
<select ID="DropDownList2" Height="18px" Width="187px">
<option Value="2013-10-10">2013-10-10 Style 1</option>
<option Value="2013-10-10">2013-10-10 Style 2</option>
<option Value="2013-10-10">2013-10-10 Style 3</option>
<option Value="2013-10-09">2013-10-09 Style 1</option>
<option Value="2013-10-09">2013-10-09 Style 2</option>
<option Value="2013-10-09">2013-10-09 Style 3</option>
<option Value="Orange">Orange Style 4</option>
<option Value="Onion">Onion Style 1</option>
<option Value="Onion">Onion Style 2</option>
<option Value="Wewe">wewe Style 2</option>
</select>
</div>
和Javascript
var options = $("#DropDownList2").html();
$("#DropDownList1").change(function(e) {
var text = $("#DropDownList1 :selected").text();
$("#DropDownList2").html(options);
if (text == "All") return;
$('#DropDownList2 :not([value^="' + text.substr(0, 3) + '"])').remove();
});
请帮助谢谢:)
答案 0 :(得分:1)
<select name="select1" id="select1">
<option Value="">All</option>
<option Value="2013-10-10">2013-10-10</option>
<option Value="2013-10-09">2013-10-09</option>
<option Value="Onion">Onion</option>
<option Value="Wewe">Wewe</option>
</select>
<select name="select2" id="select2">
<option Value="2013-10-10">2013-10-10 Style 1</option>
<option Value="2013-10-10">2013-10-10 Style 2</option>
<option Value="2013-10-10">2013-10-10 Style 3</option>
<option Value="2013-10-09">2013-10-09 Style 1</option>
<option Value="2013-10-09">2013-10-09 Style 2</option>
<option Value="2013-10-09">2013-10-09 Style 3</option>
<option Value="Orange">Orange Style 4</option>
<option Value="Onion">Onion Style 1</option>
<option Value="Onion">Onion Style 2</option>
<option Value="Wewe">wewe Style 2</option>
</select>
JS
$("#select1").change(function() {
if($(this).data('options') == undefined){
/*Taking an array of all options-2 and kind of embedding it on the select1*/
$(this).data('options',$('#select2 option').clone());
}
var id = $(this).val();
var options = $(this).data('options').filter('[value=' + id + ']');
$('#select2').html(options);
});
答案 1 :(得分:0)
获取第一个选项的长度,然后更改下面的代码。 var options = $(“#DropDownList2”)。html();
$("#DropDownList1").change(function(e) {
var text = $("#DropDownList1 :selected").text();
var len = text.length;
$("#DropDownList2").html(options);
if (text == "All") return;
$('#DropDownList2 :not([value^="' + text.substr(0, len) + '"])').remove();
});