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();
精彩评论