例1
代码如下 | 复制代码 |
<!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=utf-8" /> <title>Jquery 手动添加和删除文本框</title> </head> <script src="jquery-1.6.4.js"></script> <style> * { font-family:Arial; } h2 { padding:0 0 5px 5px; } h2 a { color: #224f99; } a { color:#999; text-decoration: none; } a:hover { color:#802727; } p { padding:0 0 5px 0; } input { padding:5px; border:1px solid #999; border-radius:4px; -moz-border-radius:4px; -web-kit-border-radius:4px; -khtml-border-radius:4px; } <div id="p_scents"> $('#addScnt').live('click', function() { $('#remScnt').live('click', function() { </script> |
例2
代码如下 | 复制代码 |
<!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=utf-8" /> <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> <script type="text/javascript"> $(document).ready( function(){ $("#theButton").click( function (){ //创建三个元素 var $txt = $("<input type='text' value='' size='20' name='theText' />"); var $btn = $("<input type='button' value='del'/>"); var $br = $("<br/>"); $btn.click( //设置删除按钮的onclick事件 function (){ $txt.remove(); $btn.remove(); $br.remove(); } ) $("#div1").append($txt).append($btn).append($br); } ) } ) </script> <title>无标题文档</title> </head> <body> <input type="button" value="add" id="theButton" /> <div id="div1"></div> </body> </html> |