这个例程展示了以html加上js动态创建新输框,最后以php接收输入。记录如下。。。
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>php输入处理</title>
</head>
<body>
<div>
<h2>账号信息处理</h2>
<button type="button" class="btn btn-success btn-sm" id="addBtn" onclick="btnAddItem()">新增</button>
<button type="button" class="btn btn-danger btn-sm" id="removeBtn">移除</button>
<script>
function btnAddItem() {
console.log("onclick btnAddItem");
var Mainform = document.getElementById("mainForm");
var zoneLabel = document.createTextNode("zoneId:");
Mainform.appendChild(zoneLabel);
var inputBox = document.createElement("input");
Mainform.appendChild(inputBox);
var zoneLabel = document.createTextNode("account:");
Mainform.appendChild(zoneLabel);
var inputBox = document.createElement("input");
Mainform.appendChild(inputBox);
var openId = document.createTextNode("openId:99999");
var br = document.createElement("br");
Mainform.appendChild(openId);
Mainform.appendChild(br);
//btnSubmit.insertBefore(inputBox,null);
}
</script>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$zoneId = $_POST["zoneId"];
$account = $_POST["account"];
$openId = $zoneId . $account;
}
?>
<form id="mainForm" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<input id="submit" type="submit" name="submit" value="Submit">
<br><br>
zoneId: <input type="text" name="zoneId" value="<?php echo $zoneId; ?>">
account: <input type="text" name="account" value="<?php echo $account; ?>">
openId: <?php echo $openId; ?>
<br>
</form>
</div>
</body>
</html>
|