javascript JSF:如何在输入字段中放置 onfocus、onblur 效果?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6767161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSF : How put onfocus, onblur effect in input field?
提问by Valter Silva
I'm thinking about how can I implement onfocus
and onblur
effects in my input field in JSF 2.0.
我正在考虑如何在 JSF 2.0 中的输入字段中实现onfocus
和onblur
影响。
I do the following in HTML:
我在 HTML 中执行以下操作:
<input type="text" name="name" id="name" size="30" value="Name (required)"
onblur="if (this.value == ''){this.value = 'Name (required)'; }"
onfocus="if (this.value == 'Name (required)') {this.value = ''; }"
class="text-input" />
Now I'm wondering how I could do this in JSF 2.0. Does anyone have an idea?
现在我想知道如何在 JSF 2.0 中做到这一点。有没有人有想法?
EDIT
编辑
I'm trying the attribute 'onblur' and 'onfocus' but still nothing appearing in my input field.
我正在尝试属性 'onblur' 和 'onfocus' 但仍然没有出现在我的输入字段中。
<h:inputText onblur="Nome" onfocus="" ></h:inputText>
回答by Jasper
You can just use the same attributes as your HTML sample. The following piece of code works just fine:
您可以使用与 HTML 示例相同的属性。下面的一段代码工作得很好:
<h:inputText id="name" value="Name (required)"
onblur="if (this.value == ''){this.value = 'Name (required)'; }"
onfocus="if (this.value == 'Name (required)') {this.value = ''; }" />
回答by OpenSource
If you do a view source on the rendered html page, does it show the html that you are looking for? - If so you are good to go or atleast it is working as designed :-). Basically whatever jsf h: type tags that you have should be rendered as equivalent html.
如果您在呈现的 html 页面上查看源代码,它是否显示您正在寻找的 html?- 如果是这样,您就可以开始了,或者至少它按设计工作:-)。基本上任何 jsf h: 类型标签都应该被呈现为等效的 html。