简体   繁体   中英

JSF : How put onfocus, onblur effect in input field?

I'm thinking about how can I implement onfocus and onblur effects in my input field in JSF 2.0.

HTML 中的示例

I do the following in 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?

EDIT

I'm trying the attribute 'onblur' and 'onfocus' but still nothing appearing in my input field.

<h:inputText onblur="Nome" onfocus="" ></h:inputText>

You can just use the same attributes as your HTML sample. The following piece of code works just fine:

<h:inputText id="name" value="Name (required)"
   onblur="if (this.value == ''){this.value = 'Name (required)'; }"
   onfocus="if (this.value == 'Name (required)') {this.value = ''; }" />

Simply use onblur attribute of <h:inputtext>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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