开发者

Text input focus loss event

开发者 https://www.devze.com 2023-02-01 19:23 出处:网络
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?

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)


At your clearTextArea method take the current text in the text area and store in into a hidden field or a cookie. Then at on blur event, check if the value changed.

0

精彩评论

暂无评论...
验证码 换一张
取 消