我有一个排序栏,我想在点击时保留网址和标题。例如,这个链接:
<a href="http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=asc ">Title ASC</a>
应改为:
<a href="http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=desc ">Title DESC</a>
链接应转到页面,然后在单击后切换到新链接。
这是怎么做到的? HTML5,Javascript还是Jquery?
答案 0 :(得分:0)
我不完全确定是不是这样,但如果可能的话,你可以尝试给出反馈。
<script>
function changeHref(_a) {
var linkAsc = "http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=asc";
var linkDesc = "http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=desc";
console.log(_a);
if (_a.id == "aOne") {
document.getElementById(_a.id).href = linkDesc;
} else {
document.getElementById(_a.id).href = linkAsc;
}
return false;
}
</script>
<强> HTML 强>
<a href="http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=asc" id="aOne" onclick="changeHref(this);">Title ASC</a>
<br />
<a href="http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=desc" id="aTwo" onclick="changeHref(this);">Title DESC</a>
答案 1 :(得分:0)
我认为这项工作:
<强> HTML 强>
<a id="link" href="http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=asc ">Title ASC</a>
<强> JS 强>
$(document).ready(function () {
if($("#link")[0].textContent == "Title ASC")
{
$("#link")[0].textContent = "Title DESC";
$("#link")[0].href = "http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=desc"
}
else
{
$("#link")[0].textContent = "Title ASC";
$("#link")[0].href = "http://localhost/11/affiliate/?post_type=affiliate&orderby=title&order=asc"
}
});
答案 2 :(得分:0)
viewWillAppear