87,988
社区成员
发帖
与我相关
我的任务
分享
<!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>无标题文档</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".btn").click(function(){
var li=$(".div1 li").eq(0).clone(true);
li.insertBefore($('.div1 li').eq($('.div1 li').length-1));
})
});
</script>
<style>
*{
margin:0;
padding:0;
}
body{
font-size:12px;
}
.div{
width:650px;
float:left;
border:1px solid #DCDCDC;
padding-bottom:20px;
}
.text{
width:100px;
height:30px;
line-height:30px;
border:1px solid #DCDCDC;
float:left;
margin:20px 0 0 20px;
display:inline;
}
.div1{
float:left;
}
.div1 li{
float:left;
width:650px;
margin-top:10px;
display:inline;
height:30px;
background:#096;
}
.btn{
float:left;
}
</style>
</head>
<body>
<div class="div">
<input class="text" type="text" />
<div class="div1">
<ul>
<li></li>
</ul>
</div>
<input class="btn" type="button" value="增加" />
</div>
</body>
</html>
$(document).ready(function() {
var num = 1;
$(".btn").click(function() {
var $v = $('.text').val();
if ($v > num) {
num++
var $li = $('<li>');
var $span = $('<span>').html('del').click(function() {
num--
$(this).parent().remove();
});
$li.append($span).appendTo($('.div ul'));
}
if(num>$v){
alert('chaolechaole');
}
})
});
<!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>无标题文档</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var htmls = $('.div1').html();
$(".btn").click(function(){
$('.div1').html(htmls);
var cont = $('input.text').val();
for(i=0;i<cont-1;i++){
var li = $(".div1 li").eq(0).clone(true);
li.insertBefore($('.div1 li').eq($('.div1 li').length-1))
}
//;
})
});
</script>
<style>
*{
margin:0;
padding:0;
}
body{
font-size:12px;
}
.div{
width:650px;
float:left;
border:1px solid #DCDCDC;
padding-bottom:20px;
}
.text{
width:100px;
height:30px;
line-height:30px;
border:1px solid #DCDCDC;
float:left;
margin:20px 0 0 20px;
display:inline;
}
.div1{
float:left;
}
.div1 li{
float:left;
width:650px;
margin-top:10px;
display:inline;
height:30px;
background:#096;
}
.btn{
float:left;
}
</style>
</head>
<body>
<div class="div">
<input class="text" type="text" />
<div class="div1">
<ul>
<li></li>
</ul>
</div>
<input class="btn" type="button" value="增加" />
</div>
</body>
</html>
$(document).ready(function() {
var num = 1;
$(".btn").click(function() {
var $v = $('.text').val();
if ($v > num) {
num++
var $li = $('<li>');
var $span = $('<span>').html('del').click(function() {
num--
$(this).parent().remove();
});
$li.append($span).appendTo($('.div ul'));
}
})
});<!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>无标题文档</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<style>
*{
margin:0;
padding:0;
}
body{
font-size:12px;
}
.div{
width:650px;
float:left;
border:1px solid #DCDCDC;
padding-bottom:20px;
}
.text{
width:100px;
height:30px;
line-height:30px;
border:1px solid #DCDCDC;
float:left;
margin:20px 0 0 20px;
display:inline;
}
.div1{
float:left;
}
.div1 li{
float:left;
width:650px;
margin-top:10px;
display:inline;
height:30px;
background:#096;
}
.btn{
float:left;
}
</style>
</head>
<body>
<div class="div">
<input class="text" type="text" />
<div class="div1">
<ul>
<li></li>
</ul>
</div>
<input class="btn" type="button" value="增加" onclick="add()" />
<script>
function add() {
var ul = $('div.div1 ul'), txt = $('input.text'), li = ul.find('li').size();
if (!/^\d+$/.test(txt.val())) { alert('为数字!'); txt.select(); return false; }
var v = parseInt(txt.val(), 10);
if (li < v) for (var i = li; i < v; i++) ul.append('<li><a href="#" onclick="$(this).parent().remove();return false">[删除]</a></li>');
else ul.find('li:gt(' + (v-1) + ')').remove();
}
</script>
</div>
</body>
</html>