开发者

add character entity from numerical identifier to input value

Im trying to add a couple of character entities to the value for the input. I can only seem add these character entities when im adding as inline say to the event handler.

Works inline to input

value="enter name –>" onfocus="if(this.value=='enter name –>'){this.value=''}; 

Dose not work as i was liking say being called form a function it di开发者_Go百科splays " –>"

if(ds.value==''){
    ds.value='enter name –>';
    }


An alternative is to use unicode:

<input value="enter name &#x2D;&#x3E;" onfocus="if(this.value=='enter name &#x2D;&#x3E;'){this.value=''};" onblur="check(this);" />

All values are in hex.

function check(ds) {
    if(ds.value==''){
        ds.value='enter name \u002D\u003E';
    }
}

Also see my jsfiddle.


You can either put direct values in your javascript, or decode them with simple javascript before assigning.

see : http://jsfiddle.net/mFtVa/1/

<input id='inline' value="enter name &#150;&gt;"  />
<input id='func_direct' value=""  />
<input id='func_entity' value=""  />

<script>

    var ds= document.getElementById('func_direct');   

    var de = document.getElementById('func_entity');           


    function decode(str)
    {
         var s = document.createElement("TEXTAREA");
         s.innerHTML = str;
         return s.value;
    }

    if(ds.value==''){    
        ds.value='enter name ->';
        }    

    if(de.value==''){   
        de.value = decode('enter name &#150;&gt');
        }


try this

ds.value='enter name \&#150;&gt;';
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜