標籤:急救電話 jquery title jquery增加刪除節點
jquery相對亦js來說在對DOM文檔操作來說非常方便,本文主要討論使用jquery對html文檔中節的刪除
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/43/CA/wKioL1Pcm4mwEHMHAADfd5AaLfM627.jpg" title="Screenshot from 2014-08-02 15:58:42.png" alt="wKioL1Pcm4mwEHMHAADfd5AaLfM627.jpg" />
如,因為是急救電話數量是不確定的,因此需要能夠靈活地添加和刪除,因此就需要用jquery來對節點進行操作。
代碼在附件中,可以正常執行,這裡只是對節點的增加和刪除中部分代碼,其他類似操作可以在此基礎上進行修改操作既可以實現。
主要代碼如下所示,主要是最後的jquery代碼注意要引用jquery才可正常執行的:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
</head>
<body>
<div class="clear" style="padding:15px;">
<span style="margin-left:15px;">急救電話</span>
<input class="fl-r" type="button" value="添加" onClick="addJJDH()"/>
</div>
<div style="margin-left:40px;margin-top:20px;" id="lxdh">
<div style="padding:10px;">
<span style="margin-top:20px;">急救電話1:</span><input name="emgcall" class="jjdh" type="text" />
<a href="#" src="" alt="刪除" /></a>
</div>
</div>
</body>
<script>
function addJJDH(){
var n= $(".jjdh").size() + 1;
$("#lxdh").append(‘<div style="padding:10px;">‘ +
‘<span style="margin-top:20px;">急救電話‘+ n + ‘:</span><input name="emgcall" class="jjdh" type="text" /> ‘ +
‘<a href="#" src="${pageContext.request.contextPath}/houtai/images//cross.png" alt="刪除" /></a></div>‘);
}
function deleteJJDH(node){
$("#lxdh>div:last-child").remove();
}
</script>
</html>
本文出自 “隨波不逐流” 部落格,請務必保留此出處http://cnhadjb.blog.51cto.com/5274430/1534190