我有一个jsp,它使用了很多标签。每个表都有一个用于用户输入字段的部分。我想为整个jsp页面提供“自动保存”功能,仅当整个页面中的某些内容发生变化时。我可以使用Javascript或Jquery。我需要一些建议,关于在闲置40秒后应该如何实施相同的建议。我看不懂每个文本框,因为它们很多。我需要一种通用的方法来知道整个页面中的任何文本框是否已更改,我需要在40秒钟不活动后保存。
<s:textfield cssClass="label" key="loeEDBCDsgnHrs" label="" cssStyle="width:50;" maxlength="5" />
您可以通过这种方式达到此目的
//This would be called if any of the input element has got a change inside the form
var changed = false;
$('form').on('keyup change paste', 'input, select, textarea', function(){
changed = true;
});
setTimeout(function(){
if(changed){
console.log($('#form').serialize());
// call your ajax or what ever to save
// changed = false;
}
},4000)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<form id="form">
<input type="text" name="first" placeholder="First Input "/>
<input type="text" name="second" placeholder="Second Input "/>
<input type="text" name="third" placeholder="Third Input "/>
</form>