开发者

javascript: how to make input selected

i have to use the following function, to change the input's type

    <input class="input" id="pas" type="text" name="password" style="color: #797272;" 
                                value= "<?php if ($_POST[password] != '') {echo '';}
                                        else {echo 'Ծածկաբառ';}?>"   
                                 onclick="if (this.value =='Ծածկաբառ') {
                                                                             this.value='';
                    开发者_高级运维                                                         this.style.color='black';
                                                                             change();
                                                                             }" 
                                                                             />
<script type="text/javascript">
    function change() 
        {
            var input=document.getElementById('pas');
            var input2= input.cloneNode(false);
            input2.type='password';
            input.parentNode.replaceChild(input2,input);
        }
</script>

it works fine, but i have to reclick on input, because it creates a new input. so what can i do, if i want it to create a new input with cursor in it? thanks

update::

input2.focus(); doesn't work in IE7


function change() 
        {
            var input=document.getElementById('pas');
            var input2= input.cloneNode(false);
            input2.type='password';
            input.parentNode.replaceChild(input2,input);
            input2.focus() <-- here you set the focus
        }


input2.focus();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜