$(selector).after(content)
after() 函数在所有匹配的元素之后插入 HTML 内容。
input验证错误,提示信息弹出:
function showMessage(inputId,msg){ msg="<span id='msg_"+inputId+"' class='hint'>"+msg+"</span>"; $("#"+inputId).after(msg); var msgId="msg_"+inputId; window.setTimeout("hideMessage('" + msgId + "')",4000); } function hideMessage(msgId){ $("#"+msgId).remove(); }
?
error信息处理,隐藏在JSP页面中的div:
<div id="ajaxEmsg" style="display:none;"> <table style="width:600px;" cellspacing="0" cellpadding="10"> <tr> <td id="msgEText"></td> </tr> </table> </div>
?
var g_ajax_msg_div = "ajaxEmsg";//ajax messge box div id var g_ajax_msg_text = "msgEText";//ajax message td id function clearErrorMessage() { var textComp = document.getElementById(g_ajax_msg_text); if (textComp != null) { textComp.innerText = ''; //$(textComp).text(""); } $("#" + g_ajax_msg_div).attr("style", "display: none;"); } function showErrorMessage(message) { var textComp = document.getElementById(g_ajax_msg_text); textComp.innerText = message;//for ie textComp.textContent= message;//for firefox $("#" + g_ajax_msg_div).attr("style", "display: true;"); scroll(0,0);//window.scroll(x,y) 窗口滚动条坐标,y控制上下移动,须与函数配合 }
?
display:none????? 隐藏对象。? 隐藏对象其物理空间
visibility:hidden? 隐藏对象。? 保留其占据的物理空间?
?
绑定ajax异步请求,发生错误时,统一响应error方法
$().ready(function() { $.ajaxSetup({ error:function(x, e) { if(x.responseText.substr(0, 11) == 'Error 490: ') { showWarning(x.responseText); }else{ showErrorMessage(x.responseText); } } }); });
?
?