在提交表单并重新加载页面后,使用jquery显示通知? [英] Displaying a notification with jquery after a form have been submited and the page reloaded?

查看:82
本文介绍了在提交表单并重新加载页面后,使用jquery显示通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道使用.submit会在单击提交按钮时触发事件。但是我想在点击提交按钮并重新加载页面时触发事件(我认为每个页面在表单提交后重新加载)。



I有这个表格



 @ using(Html.BeginForm(Feedback,Home,FormMethod.Post))
{
@ Html.ValidationSummary()

@ Html.ValidationSummary(,new {@class =text-danger})
< div class = form-group >
@ Html.LabelFor(m => m.Cell,new {@class =col-md-2 control-label})
< div class = col -md-10 >
@ Html.EditorFor(m => m.Cell,new {htmlAttributes = new {@class =form-control,placeholder =Phone Number,type =text}})
< / div >
< / div >
< div class = col-sm-6 col-sm-offset-3 >
< div class = btn-toolbar >
< 按钮 class = btn-raised btn-success btn >
提交
< div class = ripple-container > < / div >
< span class =code-keyword>< / button >
< 按钮 class = btn btn-default > 取消< / button >
< / div >
< / div >
}





我尝试过:



< script>

jQuery(文件)

.ready(function(){



jQuery(#Cel l)。inputmask(099 999 9999);



jQuery(#Cell)

.on(模糊 ,

function(){

var last = $(this).val()。substr($(this).val()。indexOf( - ) + 1);

if(last.length == 4){

var move = $(this).val()。substr($(this).val ()。indexOf( - ) - 1,1);

var lastfour = move + last;

var first = $(this).val()。 substr(0,9);

$(this).val(first +' - '+ lastfour);

}

}) ;



//检查用户是否刚提交此页面

var justSubmitted = $ .cookie('just_submitted');

if(justSubmitted){

$(#feedback)。show();

//删除cookie

$ .cookie('just_submitted',null);

}



//提交

$(表格)

.submit(function() {

//创建一个cookie,然后让它正常提交

$ .cookie('just_submitted','true');

} );





});





< / script>

解决方案

(this).val()。substr(


(this)。 val()。indexOf( - )+ 1);

if(last.length == 4){

var move =

(本).VAL()。SUBSTR(

I know that using .submit will trigger an event when the submit button is clicked. But I would like to trigger the event when the submit button have been clicked and the page reloaded (I think every page reloads after a form have been submitted).

I have this form

@using (Html.BeginForm("Feedback", "Home", FormMethod.Post))
                    {
                        @Html.ValidationSummary()

@Html.ValidationSummary("", new {@class = "text-danger"})
                        <div class="form-group">
                            @Html.LabelFor(m => m.Cell, new {@class = "col-md-2 control-label"})
                            <div class="col-md-10">
                                @Html.EditorFor(m => m.Cell, new {htmlAttributes = new {@class = "form-control", placeholder = "Phone Number", type = "text"}})
                            </div>
                        </div>
<div class="col-sm-6 col-sm-offset-3">
                            <div class="btn-toolbar">
                                <button class="btn-raised btn-success btn">
                                    Submit
                                    <div class="ripple-container"></div>
                                </button>
                                <button class="btn btn-default">Cancel</button>
                            </div>
                        </div>
}



What I have tried:

<script>
jQuery(document)
.ready(function() {

jQuery("#Cell").inputmask("099 999 9999");

jQuery("#Cell")
.on("blur",
function() {
var last = $(this).val().substr($(this).val().indexOf("-") + 1);
if (last.length == 4) {
var move = $(this).val().substr($(this).val().indexOf("-") - 1, 1);
var lastfour = move + last;
var first = $(this).val().substr(0, 9);
$(this).val(first + '-' + lastfour);
}
});

// check if user just submitted this page
var justSubmitted = $.cookie('just_submitted');
if (justSubmitted) {
$("#feedback").show();
// delete the cookie
$.cookie('just_submitted', null);
}

// submited
$("form")
.submit(function() {
// create a cookie, then let it submit normally
$.cookie('just_submitted', 'true');
});


});


</script>

解决方案

(this).val().substr(


(this).val().indexOf("-") + 1);
if (last.length == 4) {
var move =


(this).val().substr(


这篇关于在提交表单并重新加载页面后,使用jquery显示通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆