我使用 php 自动生成密码。我将生成的密码存储在一个变量中。在这里,我通过使用按钮上的 ONCLICK 属性将这些生成的密码分配给文本框(按钮名称为“生成密码”)。但我没有得到所需的输出(通过单击该按钮,密码必须在文本框中可见)。在这里,我附上了相应的代码。谁能告诉我做错了什么??
<!DOCTYPE html>
<html>
<head>
<title>create_profile</title>
<link rel="stylesheet" type="text/css" href="create_profile.css" />
<script type="text/javascript">
function getPassword(){
document.getElementById("password").value="<?php
// Characters to use for the password
$str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
// Desired length of the password
$pwlen = 8;
// Length of the string to take characters from
$len = strlen($str);
// RANDOM.ORG - We are pulling our list of random numbers as a
// single request, instead of iterating over each character individually
$uri = "http://www.random.org/integers/?";
$random = file_get_contents(
$uri ."num=$pwlen&min=0&max=".($len-1)."&col=1&base=10&format=plain&rnd=new"
);
$indexes = explode("\n", $random);
array_pop($indexes);
// We now have an array of random indexes which we will use to build our password
$pw = '';
foreach ($indexes as $int){
$pw .= substr($str, $int, 1);
}
回声 $pw;
?>"; }
</script>
<h1> Create Profile </h1>
<label for="name">name:</label><br />
<input id="name" name="name" type="text" size="30" /><br />
<label for="user_id">user id:</label><br />
<input id="user_id" name="user_id" type="text" size="30" /><br />
<label for="email">Your Email:</label><br />
<input id="email" name="email" type="text" size="60" /><br />
<label for="password">password:</label><br />
<input id="password" name="password" size = "10" /> <br/>
<button onclick="getpassword();" >Generate Password</button>