使用jquery增加、刪除html文檔節點

來源:互聯網
上載者:User

標籤:急救電話   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" />&nbsp;‘ +
                      ‘<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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.