开发者

Running code when the page is loaded

I have this link that fills a开发者_开发问答n input when clicked.

<a href="#" onclick="javascript:document.getElementById('input').value='<?php echo("$ms"); ?>'">

I was wondering how I would get it to do this automatically onload.


I usually put it in onload, don't know if there is a best practise:

<body onload="myFunc()">


Assuming $ms has been made safe for XSS:

<input value="<?php echo $ms; ?>">


You can use the onload property of an element :

<body onload="javascript:document.getElementById('input').value='<?php echo("$ms"); ?>'">


Add the onLoad event to the <body> element of your document:

<body onload="javascript:document.getElementById('input').value='<?php echo("$ms"); ?>'">

Furthermore, it looks like you are using PHP, if you just want to use $ms to set the value of #input you could also use something like:

<?php
echo '<input type="text" id="input" value="'.$ms.'"/>
?>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜