Bạn có thể thử một cái gì đó như thế này:
HTML phần:
<html>
<head></head>
<body>
<body>
</html>
Các javascript:
<script>
//create a form
var f = document.createElement("form");
f.setAttribute('method',"post");
f.setAttribute('action',"submit.php");
//create input element
var i = document.createElement("input");
i.type = "text";
i.name = "user_name";
i.id = "user_name1";
//create a checkbox
var c = document.createElement("input");
c.type = "checkbox";
c.id = "checkbox1";
c.name = "check1";
//create a button
var s = document.createElement("input");
s.type = "submit";
s.value = "Submit";
// add all elements to the form
f.appendChild(i);
f.appendChild(c);
f.appendChild(s);
// add the form inside the body
$("body").append(f); //using jQuery or
document.getElementsByTagName('body')[0].appendChild(f); //pure javascript
</script>
này cách bạn có thể tạo nhiều phần tử như bạn muốn động.
Về cơ bản, chính xác khi bạn tạo các phần tử khác bằng JavaScript, sử dụng 'createElement' hoặc jQuery. Bạn có thể sử dụng jQuery không? –
Có, tôi có thể sử dụng jQuery, không quá familliar với nó mặc dù. – Odyss3us