【问题标题】:JS pageshow event triggerring on form validationJS pageshow事件触发表单验证
【发布时间】:2014-10-29 04:15:03
【问题描述】:

所以我有下面的 JS 来显示加载 GIF,而我的 servlet 添加一些数据然后重定向。当我提交表单时,它会触发点击事件没有问题。但是在它运行页面显示并再次隐藏 div 之后。这对我来说毫无意义,我仍然在同一页上。 pageshow 的重点是如果有人点击返回,页面不会卡在加载的 GIF 上。为什么验证检查后会触发页面显示?我错过了什么

// ==== [START] Search gif hide and show ====
$("#equipSrch").click(function () {
    if ($("#search-form").valid()) {
        document.getElementById("viewSrch").style.display = 'none';
        document.getElementById("loading").style.display = 'block';
    }
});

$(window).bind('pageshow', function () {
    document.getElementById("viewSrch").style.display = 'block';
    document.getElementById("loading").style.display = 'none';
});
// ==== [END] Search gif hide and show ====
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

【问题讨论】:

  • 你是不是在某个地方触发了“pageshow”?

标签: javascript jquery html


【解决方案1】:

我错过了一些 jquery 导入,valid() 函数正在触发,但我之前错过了一个异常。我也没有先调用 validate() 函数。

	// ==== [START] Search gif hide and show ====
	$("#submit").click(function() {
		$("#search-form").validate();
		if($("#search-form").valid()) {
			document.getElementById("viewSrch").style.display = 'none';
			document.getElementById("loading").style.display = 'block';
		}
	});
	
	$(window).bind('pageshow', function() {
		document.getElementById("viewSrch").style.display = 'block';
		document.getElementById("loading").style.display = 'none';
	 });
	// ==== [END] Search gif hide and show ====
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/additional-methods.min.js"></script>

【讨论】:

    猜你喜欢
    • 2015-07-13
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 2014-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多