用jquery動(dòng)態(tài)添加刪除html元素:
首先要下載并加載jquery.js文件.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title>用jquery動(dòng)態(tài)添加刪除html元素標(biāo)簽</title>
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var spotMax = 3;
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_addr" /> ' +
'<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>
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。