JS 通过点击事件动态添加文本框

时间:2020-12-23 05:02:38

直接拷贝到浏览器就能实现

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Change.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script language="javascript">
function test4(event) {
if(event.value == "11") {
var div3 = document.getElementById("div3");
div3.innerHTML ="<form><input type='text' name='s' value='xx'></form>";
}
if(event.value == "22") {
var div3 = document.getElementById("div3");
div3.innerHTML ="";
}
}
</script>
</head>
<body>
<input type="text" id="div2" value=""/>
<div id="div3"></div>
<input type="button" value="11" onclick="test4(this)"/>
<input type="button" value="22" onclick="test4(this)"/> </body>
</html>