看板 Ajax 關於我們 聯絡資訊
小弟現在有一個問題請教大家 在body內有一段內容 <div class="divimg" style="top: 100px; left: 50px; z-index: 1;"> <a name="link" href="#">連接</a> <button onclick="selfdb(this); return false;" type="button" name="selfdb">按鈕 1</button> <button onclick="pubdb(this); return false;" type="button" name="publicdb">按鈕2</button> <input type="text" style="width: 10%;" value="1" name="floor">內容 <img src="img/poster2.jpg"> </div> 想要 (1)按下『按鈕1』時 (2)將上面整個div內容 去除按鈕1的button整個標籤 (3)再將整個div存成變數 先引用了一個outerHTML.js去抓外部的標籤 outerHTML.js內容如下『 (function($) { $.fn.outerHTML = function(s) { return (s) ? this.before(s).remove():$('<p>').append(this.eq(0).clone()).html(); } })(jQuery); 』 引發的selfdb()function如下 selfdb=function(self){ var front=$(self).parent().outHTML(); alert("front="+front); //可以出現整個DIV沒問題 var frontok=$(front).find("button:eq(0)").remove(); alert("frontok="+frontok.outerHTML()); 這裡卻沒辦法移除『按鈕1』整個標籤 在最後的frontok的alert卻出現 整個按鈕1的標籤 <button onclick="selfdb(this); return false;" type="button" name="selfdb">按鈕 1</button> 變成跟 var frontok=$(front).find("button:eq(0)")一樣 有沒有加入remove()都沒有差... 這要如何去做呢? 後面的button好像無法remove 要怎樣才能達到我要的效果呢?請教~感謝... -- 寧願天空是藍色~ 也不願心情是藍的! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.17.52.209 ※ 編輯: robinnpca 來自: 163.17.52.209 (12/06 10:29)
kerash:沒試過,單純先問一下 .. return 後還能做動作嗎? 12/06 10:33
knives:稍微修改了一下http://jsfiddle.net/TBhuc/ 看是不是你要的 12/06 11:22
robinnpca:return完後還可以做動作防止form做summit出去 12/06 13:08
robinnpca:大概類似!不過我的內容中有很多這類似的DIV所以不用id 12/06 13:09
robinnpca:用name或其他的指標..感謝參考後已成功^^ 12/06 13:09