首页 > Web开发 > 详细

JQuery实现点击按钮动态添加input文本框,限制个数

时间:2015-07-15 10:51:25      阅读:951      评论:0      收藏:0      [点我收藏+]

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>

<script src="jquery-min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
  var spotMax = 30;
  if($(‘div.spot‘).size() >= spotMax) {$(obj).hide();}
  $("input#add").click(function(){     addSpot(this, spotMax);
  });
});

function addSpot(obj, sm) {
$(‘div#spots‘).append(
    ‘<div class="spot">‘ +
    ‘<input type="text" name="spot_title" /> ‘ +
    ‘<input type="text" name="spot_url" />  ‘ +
    ‘<input type="button" class="remove" value="Delete" /></div>‘)
  .find("input.remove").click(function(){
    $(this).parent().remove();
    $(‘input#add‘).show();
  });

  if($(‘div.spot‘).size() >= sm) {$(obj).hide();}
};
</script>
</head>

<body>
<form action="test.php" method="post"  name="asdf" id="asdf">
  <div id="spots">
    <input type="button" id="add" name="add" value="add" /><br />
  </div>
  <input type="button" name="Submit" value="Submit" id="send" />
</form>
<script>
  $(‘#send‘).click(function(){
  alert(‘Demonstration Only: submit disabled‘);
});
</script>
</body>
</html>

 

 

技术分享

JQuery实现点击按钮动态添加input文本框,限制个数

原文:http://www.cnblogs.com/chencheng365/p/4647406.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!