javascript - Setting placeholder att in IE9 -


I have the following code that is based on button clicks.

  Click the function YES () {$ ('# & lt;% = txtMsg.ClientID% & gt;'). Ether ('placeholder', 'tell me more'); }  

The button has been declared as

  

The problem is that there is a need to set the placeholder on a dynamically based basis in Chrome and Firefox, but the behavior is correct, but not added when using IE9 placeholder attribute Was there.

How can I manage this cross browser

thanks

Yes placeholder is not supported by IE 9 but you can easily see some options such as JavaScript to get it

  & lt; Input type = "text" placeholder = "test" value = "placeholder text" onfocus = "if (this .value == 'placeholder text') this.value = ''" onblur = "If (this.value == ' ') This.value =' placeholder text '"/>  

But while using this approach you should take care of this approach to set the value to textbox . So when you retrieve it, you get the value. So whenever you use it, you have to check the placeholder value.

Your function will be like this

  function ClickYes () {// $ ('#txtmsg') for modern browsers. Ether ('placeholder', 'tell me more'); // $ ('# txtMsg') for old browsers Val ('tell me more'); $ ('# TxtMsg') CSS ('color', '# ccc'). }  

You now need to handle focus and blurring events to complete it

 <($ (This) .val () == 'tell me more') {$ (this) (code ($) () ($ (document) .ready (function () {$ ("# txtMsg") .val (''); $ (this) .css ('color', 'black');}}) $ ("# txtMsg"). Blur (function () {if (! $ (This) .val ($) ($) ($) ($) ($) (Value) .val ('tell me more'); $ ('# txtMsg'). CSS ('color', '#ccc');}});});  < / Pre> 


Comments