简体   繁体   English

当用户离开页面时,如何跟踪何时在表单中输入什么文本?

[英]How do I keep track of when what is the text entered in the form when the user navigates away from the page?

I have a piece of code like this. 我有一段这样的代码。

<form method="get" action="{$self}" name="addcommentform">
<textarea title="{$enterComment}" name="comment" class="commentarea" </textarea>
<input class="Button" type="submit" value="{$postComment}" />
</form>

How do I keep track of when what is the text entered in the form's textarea when the user navigates away from the page? 当用户离开页面时,如何跟踪何时在表单的文本区域中输入什么文本? I want to prompt the user with a warning message so he/she doesn't lose the text. 我想用警告消息提示用户,这样他/她就不会丢失文本。

Thanks. 谢谢。

You could use the javascript/jquery blur event, and if the user hasn't clicked the desired button have it display the form values. 您可以使用javascript / jquery blur事件,如果用户未单击所需的按钮,它将显示表单值。 This might help JQuery Blur Validation Problem 这可能有助于JQuery模糊验证问题

Stu 斯图

Take a look at this Javascript code snippet: 看一下这个Javascript代码片段:

http://www.boutell.com/newfaq/creating/disableclose.html http://www.boutell.com/newfaq/creating/disableclose.html

This takes advantage of the window's onbeforeunload event which fires when the user is about to leave the page. 这利用了窗口的onbeforeunload事件,该事件在用户即将离开页面时触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails-如何保存表单数据并在用户导航回页面时进行检索 - Rails - How to save form data and retrieve it when user navigates back to the page 输入文本时如何更改 PDF 表单字段背景? - How do I change PDF form field backgrounds when text is entered into them? PHP表单,未输入任何文本 - PHP Form, when no text is entered 用户附加文件时如何保留以前的表单条目 - How do I keep previous form entry when the user attaches a file 如何从表单集中保留子表单的当前用户? - How do I keep the current user for a child form from a formset? 当用户在菜单外单击时,如何使我的WPF上下文菜单消失? - How do I make my WPF Context Menu go away when the user clicks outside the menu? 单击“后退”按钮时如何保留表单数据 - How do I keep form data when Back button is clicked Rails 7 + Turbo:Turbo 在收到 422 无法处理的实体时导航离开 - Rails 7 + Turbo: Turbo navigates away when receiving 422 unprocessable entity 如何在用户成功提交表单后重定向到另一个页面? - How do I redirect to another page when a user successfully submits a form? 在JS中使用Keypress事件时,如何允许输入文本 - How do I allow Text to be entered, when using Keypress event in JS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM