1

我试图让一个按钮在每次单击按钮时显示警报。目前,它仅在我第一次单击时触发,我必须刷新页面才能使其再次工作。因为这是一个提交和新建按钮,所以我需要它能够保留重新加载时会丢失的表单值。警报用于向用户提供反馈。这是我的代码:

$('input[value="Submit and New"]').on('click', function(){
alert('The request form has been submitted successfully. To submit a new form for the same user, change the form values and click on either the "Submit" or "Submit and New" button');
});
4

2 回答 2

1

使用文档设置单击,它应该可以正常工作

   $(document).on('click','input[value="Submit and New"]', function(){
    alert('The request form has been submitted successfully. To submit a new form for the same user, change the form values and click on either the "Submit" or "Submit and New" button');
    });

http://jsfiddle.net/w4QWu/

于 2013-04-16T17:56:12.253 回答
0

您可能在加载文档之前调用该函数,试试这个:

$(document).ready(function(){
    $('input[value="Submit and New"]').on('click', function(){
alert('The request form has been submitted successfully. To submit a new form for the same user, change the form values and click on either the "Submit" or "Submit and New" button');
    }
})

jsfiddle

于 2013-04-16T18:01:19.660 回答