如果不为空,如何在加载时用文本替换输入,如果最初为空并键入,如何在模糊时替换输入? [英] How to replace input with text on load if not empty, but also on blur if initially empty and typed into?

查看:113
本文介绍了如果不为空,如何在加载时用文本替换输入,如果最初为空并键入,如何在模糊时替换输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我改进以下脚本: http://jsfiddle.net/n9BkM/8/

我需要以下功能:

  • 输入字段的值属性可以为空-然后像现在一样显示(输入带有更改按钮的显示div之后)
  • 输入已经具有一定的价值-页面加载之前可能会有一些价值( http://jsfiddle.net/n9BkM/9/)-然后显示带有更改按钮的div

如何实现保存第一个功能的第二步?

非常感谢!

解决方案

您需要将对div逻辑的开关删除为一个函数,然后像现在一样在blur上以及在页面加载时调用它./p>

像这样: http://jsfiddle.net/KVDBB/

注意:我已经更改了HTML,使其在输入中具有值.再次将其清空,您将看到它像以前一样工作.

Please help me to improve the following script: http://jsfiddle.net/n9BkM/8/

I need the following fucntionality:

  • Value attribute of input field can be blank - then it shows just like now (after entering showing div with change button)
  • Input already has some value - there can be some value before the page loads ( http://jsfiddle.net/n9BkM/9/ ) - then it shows the div with change button

How to implement the second step saving the first one functionality?

Many thanks!

解决方案

You need to remove the switch to div logic into a function and then call it on blur like you are doing now, and also on page load.

Like this: http://jsfiddle.net/KVDBB/

Note: I've altered the HTML to have a value inside the input. Make it empty again and you'll see it works as before.

这篇关于如果不为空,如何在加载时用文本替换输入,如果最初为空并键入,如何在模糊时替换输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆