我需要知道我的函数有什么错误,因为当我在我的过滤器按钮上更改选择一个选项时它不起作用你能不能帮我这个是我的代码。
$("#date_employed").on("change", function() {
var selected = this.value;
if (selected != "All") {
rows.filter("[name=" + selected + "]").show();
rows.not("[name=" + selected + "]").hide();
var visibleRows = rows.filter("[name=" + selected + "]");
} else {
rows.show();
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" name="action" id="action" class="btn btn-warning">Add</button>
<select id="date_employed" class="btn btn-danger dropdown-toggle">
<option value="choose">Filter</option>
<option value="first_name">First Name</option>
<option value="last_name">Last Name</option>
</select>
答案 0 :(得分:0)
&lt; / script缺失&gt;你有});很多人:
<script>
$("#date_employed").on("change", function(){
var selected = this.value;
if(selected != "All"){
rows.filter("[name="+selected+"]").show();
rows.not("[name="+selected+"]").hide();
var visibleRows = rows.filter("[name="+selected+"]");
}
else {
rows.show();
}
});
</script>
<button type="button" name="action" id="action" class="btn btn-warning">Add</button>
<select id="date_employed" class="btn btn-danger dropdown-toggle">
<option value="choose">Filter</option>
<option value="first_name">First Name</option>
<option value="last_name">Last Name</option>
</select>
你也可以这样做:
var selected = $(this).val();