日期:2014-05-17  浏览次数:20595 次

jquery删除节点 jquery删除html标签
jquery删除节点 jquery删除html标签

先看效果:
<DIV id="Previewpics">
  <LI id="fileid16"><IMG src="http://127.0.0.1/uploads/201005/127311533698.gif.thumb_100_75.jpg"><BR>
      <INPUT onclick="window.open(this.src)" type="button" src="uploads/201005/127311533698.gif" value="大图">
    <INPUT onclick="deleteimg(this.src)" type="button" src="16" value="删除">
  </LI>
  <LI id="fileid17"><IMG src="http://127.0.0.1/uploads/201005/127311534291.jpg.thumb_100_75.jpg"><BR>
      <INPUT onclick="window.open(this.src)" type="button" src="uploads/201005/127311534291.jpg" value="大图">
    <INPUT onclick="deleteimg(this.src)" type="button" src="17" value="删除">
  </LI>
  <LI id="fileid18"><IMG src="http://127.0.0.1/uploads/201005/127311536399.gif.thumb_100_75.jpg"><BR>
      <INPUT onclick="window.open(this.src)" type="button" src="uploads/201005/127311536399.gif" value="大图">
    <INPUT onclick="deleteimg(this.src)" type="button" src="18" value="删除">
  </LI>
</DIV>


再看执行js后效果:
<DIV id="Previewpics">
  <LI id="fileid16"><IMG src="http://127.0.0.1/uploads/201005/127311533698.gif.thumb_100_75.jpg"><BR>
      <INPUT onclick="window.open(this.src)" type="button" src="uploads/201005/127311533698.gif" value="大图">
    <INPUT onclick="deleteimg(this.src)" type="button" src="16" value="删除">
  </LI>
  <LI id="fileid17"><IMG src="http://127.0.0.1/uploads/201005/127311534291.jpg.thumb_100_75.jpg"><BR>
      <INPUT onclick="window.open(this.src)" type="button" src="uploads/201005/127311534291.jpg" value="大图">
    <INPUT onclick="deleteimg(this.src)" type="button" src="17" value="删除">
  </LI>
</DIV>


对比一下就知道啦.li的id为fileid18的被删除了.
主要代码如下:
$('li').remove('#fileid'+fid);

解释一下,删除li节点,并且这个li的id为 fileidx .