01.
<!DOCTYPE HTML>
02.
<html>
03.
<head>
04.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
05.
<title>Untitled Document</title>
06.
<script src=
"jquery-1.7.1.min.js"
></script>
07.
<script>
08.
$(
function
() {
09.
var
scntDiv = $(
'#p_scents'
);
10.
var
i = $(
'#p_scents p'
).size() + 1;
11.
12.
$(
'#addScnt'
).live(
'click'
,
function
() {
13.
$(
'<p>เพิ่มข้อมูลลำดับ '
+ i +
'<label for="p_scnts"><input type="text" id="p_scnt'
+ i +
' " size="20" name="p_scnt_'
+ i +
'" value="" placeholder="Input Value" /></label> <a href="#" class="remScnt">Remove</a></p>'
).appendTo(scntDiv);
14.
i++;
15.
return
false
;
16.
});
17.
18.
$(
'.remScnt'
).live(
'click'
,
function
() {
19.
if
( i > 2 ) {
20.
$(
this
).parents(
'p'
).remove();
21.
i--;
22.
}
23.
return
false
;
24.
});
25.
});
26.
</script>
27.
</head>
28.
29.
<body>
30.
<h2><a href=
"#"
id=
"addScnt"
>ปุ่มเพิ่มข้อมูล</a></h2>
31.
<div id=
"p_scents"
>
32.
<p>
33.
เพิ่มข้อมูลลำดับ 1 <label
for
=
"p_scnts"
><input type=
"text"
id=
"p_scnt"
size=
"20"
name=
"p_scnt"
value=
""
placeholder=
"Input Value"
/></label>
34.
</p>
35.
</div>
36.
</body>
37.
</html>