简体   繁体   English

文字输入焦点丢失事件

[英]Text input focus loss event

I have the following page. 我有以下页面。 I want to restore the input text if it has not been changed(when the focus is lost). 我想恢复输入的文本,如果它没有被更改(当焦点丢失时)。 How can I do this? 我怎样才能做到这一点?


<html>
<head>
</head>
<body>

<script type="text/javascript">
function clearTextArea(object){
    object.value = "";
}
</script>

<input type="text" id="option" value="test" onfocus="clearTextArea(this);"></input>
</body>
</html>

Is there anything against using an 有什么反对使用

<input (...) onblur="this.value = 'test'">

listener? 听众?

(You can also do the same thing using a "placeholder" attribute if youre working with HTML5) (如果您使用的是HTML5,也可以使用“占位符”属性执行相同的操作)

At your clearTextArea method take the current text in the text area and store in into a hidden field or a cookie. 在您的clearTextArea方法中,将当前文本放在文本区域中,然后存储在隐藏字段或cookie中。 Then at on blur event, check if the value changed. 然后在发生模糊事件时,检查值是否更改。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM