首先定义两个默认值,默认为空查询所有,写一个提交方法用来提交ajax请求,点击事件通过类选择器获取a标签的内容并赋值给先前定义的变量,然后调用提交方法。
$(function () {
$category = “”;
$sort = “”;
$("#leibie1 li").click(function () {
$(this).addClass(“selected”).siblings(“li”).removeClass();
});
$("#leibie2 li").click(function () {
$(this).addClass(“selected”).siblings(“li”).removeClass();
$category = $(this).find(“a”).html();
tijiao();
});
$("#leibie3 li").click(function () {
$(this).addClass(“selected”).siblings(“li”).removeClass();
$sort =
(
t
h
i
s
)
.
f
i
n
d
(
"
a
"
)
.
h
t
m
l
(
)
;
/
∗
a
l
e
r
t
(
(this).find("a").html(); /*alert(
(this).find("a").html();/∗alert(("#leibie2 .selected").html());*/
tijiao();
});
function tijiao() {
if ($sort == "最新" || $sort == "全部") {
$sort = "zx";
}
else {
$sort = "zr";
}
$.ajax({
url: '${pageContext.request.contextPath}/search',
data: {'category': $category, 'sort': $sort},
dataType: 'json',
type: 'post',
success: function (data) {
alert(data[0].title + "vb123123123asdadasd");
}
});
}
});