- <!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>
JQuery实现动态增加和删除文本框
最新推荐文章于 2022-09-20 18:48:41 发布