JQuery实现动态增加和删除文本框
JQuery实现动态增加和删除文本框
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
- <title>Untitled Document</title>
- <mce:script type="text/javascript" src="jquery-1.4.2.js" mce_src="jquery-1.4.2.js"></mce:script>
- <mce:script type="text/javascript"><!--
- $(function(){
- var i = 2;
- $('#addTextImput').click(function(){
- if(i < 100) {
- $('#main').append('<div><input type="text" name="text" + i + ""/><input type="button" id="del-text" value="删除"></div>');
- i++;
- } else {
- alert("最多加100个");
- }
- });
- $('.del-text').live('click',function(){
- $(this).parent().remove();
- i--;
- });
- $('#del-text').live('click',function(){
- $(this).parent().remove();
- i--;
- });
- });
- // --></mce:script>
- </head>
- <body>
- <div id="main">
- <div><input type="text" name="text1"/></div>
- </div>
- <input type="button" id="addTextImput" value="添加"/>
- </body>
- </html>
相关推荐
IT之家 2020-03-11
graseed 2020-10-28
zbkyumlei 2020-10-12
SXIAOYI 2020-09-16
jinhao 2020-09-07
impress 2020-08-26
liuqipao 2020-07-07
淡风wisdon大大 2020-06-06
yoohsummer 2020-06-01
chenjia00 2020-05-29
baike 2020-05-19
扭来不叫牛奶 2020-05-08
hxmilyy 2020-05-11
黎豆子 2020-05-07
xiongweiwei00 2020-04-29
Cypress 2020-04-25
冰蝶 2020-04-20