一、页面跳转

1、使用location

<script type="text/javascript">
window.onload=function(){
//location.href="/login!loginInput.action";
location.replace("${pageContext.request.contextPath}/login!loginInput.action");
}
</script>

2、使用jsp标签

<jsp:forward page="/login!loginInput.action" ></jsp:forward>

二、关闭链接
1、返回false

<s:a action="role_delete?id=%{id}" onclick="return false">删除</s:a><br/>

2、返回确定对话框

<s:a action="role_delete?id=%{id}" onclick="return confirm('确定要删除吗?')">删除</s:a><br/>

三、刷新父窗口:

// 在被嵌套时就刷新上级窗口
if(window.parent != window){
window.parent.location.reload(true);
}

四、回车提交表单:

$('#user_reg_regForm input').bind('keyup', function(event) {/* 增加回车提交功能 */
if (event.keyCode == '13') {
$('#user_reg_regForm').submit();
}
});

五、表单聚焦:

window.setTimeout(function() {
$('#user_login_loginForm input[name=name]').focus();
}, 0);

六、在方法中传递String与int类型变量:

var id = "aaa";
var rowIndex = 1;
var div = '<a href="#" onclick="deleteForce(\''+id+'\', '+rowIndex+')">强制删除</a>';

七、jQuery中json对象与json字符串互换

json字符串转json对象:jQuery.parseJSON(jsonStr);
json对象转json字符串:JSON.stringify(jsonObj);

IE中可能对unicode使用“\uXXXX”格式来编码,可以使用如下来解码:
function unicode2Char(str) {
return (str.replace(/\\/g, "%"));
}

八、提交表单

$.ajax({
cache: true,
type: "POST",
url:ajaxCallUrl,
data:$('#yourformid').serialize(),// 你的formid
async: false,
error: function(request) {
alert("Connection error");
},
success: function(data) {
$("#commonLayout_appcreshi").parent().html(data);
}
});