超链接a标签运用ajax实现动态无刷新的另一种实现思路,在此为了避免A便签实现查询时向服务器回发的现象,变相的运用了input便签即按钮的客户端的办法实现ajax的动态无刷新的查询实现效果。
比如菜单的查询结果显示,本意使用超链接来实现查询功能,后来想到了让用户好的体验,使用ajax的动态无刷新的查询实现。这里给出了具体的实现代码,给用户我的实现思路的启示。有疑问的地方可以回复问我的。
<div class="rightmenu_head"><h1>目录分类</h1></div>
<div class="rightmenu_normal">
<span>◎</span>
<input type="button" id='rm-1' hidefocus="hidefocus" title='所有目录' onclick='loadInformation("?cat="+-1, -1)' value='所有目录' />
</div>
<div class="rightmenu_normal">
<span>◎</span>
<input type="button" id='rm28' hidefocus="hidefocus" title='音乐' onclick='loadInformation("?cat="+28, 28)' value='音乐' />
</div>
<div class="rightmenu_normal">
<span>◎</span>
<input type="button" id='rm19' hidefocus="hidefocus" title='公告' onclick='loadInformation("?cat="+19, 19)' value='公告' />
</div>
<div class="rightmenu_bottom"></div>function loadCurrentArticles(paraInfo) {
lockscreen();
//alert(paraInfo);
var url = "GetArticles.aspx" + paraInfo;
// 1. 创建XMLHttpRequest组件
var xhr = createXMLHttpRequest();
// 2. 设置回调函数
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
//selectCategoryMenu(orderId, count);
document.getElementById("content_product").innerHTML = xhr.responseText;
unLockScreen();
}
};
// 3. 初始化XMLHttpRequest组件
xhr.open("GET", url, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(null);
}
function loadInformation(paraInfo, categoryId) {
loadCurrentArticles(paraInfo);
var fid = document.getElementById('rightmenu');
var box = fid.getElementsByTagName('input');
for (var i = 0; i < box.length; i++) {
if (box[i].id == ("rm" + categoryId)) {
box[i].parentNode.className = "rightmenu_select";
} else {
box[i].parentNode.className = "rightmenu_normal";
}
}
}
window.onload = function () {
var categoryId = '<%=CategoryId %>';
var relevantCategoryId = '<%=RelevantCategoryId %>';
if (relevantCategoryId > 0) {
loadInformation("?relevantCat=" + relevantCategoryId, relevantCategoryId);
} else {
loadInformation("?cat=" + categoryId, categoryId);
}
};