我需要以下帮助;当在另一个输入字段中单击“gww”按钮时,我想显示一个新生成的密码(php 中的函数)。有人可以解释一下吗?
<td><input type="button" value="Generate" name="gww"></td>
<td><input type="text" id="ww"></td>
<script type="text/javascript">
function password()
{
var elem = document.getElementById("ww");
elem.value = "<? echo random_Password(); ?>";
}
</script>
function random_Password($length = 8)
{
//empty password string
$password = "";
//Possible characters
$karakters = "123456789abcdefghijklmnpqrstuvwxyz";
$maxlength = strlen($karakters);
if($length > $maxlength)
{
$length = $maxlength;
}
$i = 0;
while($i < $length)
{
$char = substr($karakters, mt_rand(0, $maxlength-1), 1);
if(!strstr($password, $char))
{
$password .= $char;
$i++;
}
}
return $password;
}