2013-12-22 13 views
4
if(count($father1)!=0) { 
      for($i=0;$i<count($father1);$i++) { 
       if($father1[$i][ 'sbs_f_userid']==$id) { 
        $pc_pic=$father1[$i][ 'sbs_f_face']. '.'.$father1[$i][ 'sbs_f_format']; 
        echo '<div class="fpic"><img src="'.$img_loc.'del-but.png" class="myfamily29 dpic f" alt="Click to Delete" title="Click to Delete"/><div class="kpic f"><img src="'.$img_gearup.$pc_pic. '" width="47" height="47" ></div></div>'; 
?> 

我在我的程序中使用此代碼。該類FPIC使一個具有棕色邊框,它有一個父親的圖片和del-but.png圖像。所以當用戶點擊del-but.png時,下面的過程運行。整個div是刪除而不是圖像

$(".dpic").click(function() { 

           if ($(this).hasClass("f")) {q = father ; var ddpic = $(this).parent('div').find(".kpic").find("img").attr("src"); var that = $(this).parent('.fpic');} 
            lbox = new LadduBox(); 
            lbox.init({ 
               "width": 485, 
               "height": 232, 
               "HTML": '<div style="width:488px; height:235px; background:url('+img_loc+'bg4.png) no-repeat;"><table cellspacing="0" cellpadding="0" border="0" align="center" width="488" height="152" style="font-family:arial; font-size:18px; font-weight:bold; color:#ffffff;"><tr><td align="right" height="50" valign="top" colspan="2"></td></tr><tr><td align="center">Are you sure you want to delete the picture?</td></tr><tr><td align="center"><div class=" abc yes">YES</div><div class="no" id="btnClose">NO</div></td></tr></table></div>', 
               'btnCloseId': '#btnClose' 
            }); 
            lbox.fire(); 
            $(".abc").bind("click", function() { 
              $.blockUI({ message: '<h3>deleting...</h3>', css: { 
                border: 'none', 
                padding: '15px', 
                'z-index': '1991000', 
                background: 'url('+img_loc+'bg4.png)', 
                   '-webkit-border-radius': '10px', 
                   '-moz-border-radius': '10px', 
                color: '#fff' 
              } 
              }); 
            $.post("delete_pic.php", { 
              "ddpic": ddpic, 
              "user": q, 
              "uid": sbs.userid 
            }, function (data) { 
            if (data.result == "1") { 
             if(q == "kid"){ $(".kidd").find("img").attr('src',''+img_loc+'blank_face.png');} 
              if(q == "mother"){ $(".mat").find("img").attr('src',''+img_loc+'blank_face.png');} 
               if(q == "father"){ $(".fat").find("img").attr('src',''+img_loc+'blank_face.png');} 
            } 
                that.remove(); 
                setTimeout($.unblockUI, 100); 
            }, "json"); 
            lbox.closeladdubox(); 
            }); 
        }); 
        } 
    }); 

用戶點擊後,會詢問你是否確定要刪除?如果是按鈕,用戶點擊即可全班靈活插卡被刪除

回答

2

div被刪除,因爲你已經定義了是

var that = $(this).parent('.fpic'); // i.e. <div class="fpic"> 

然後在第二個腳本,你正在做的

that.remove(); 

要卸下內的每一個圖像:

that.find('img').remove()

UPDATE

取出後,添加一個新的形象。你必須這樣做:

that.append('<img src="path\to\image.png" />');

總之你必須這樣做:

that.find('img').remove() // remove all the images inside 
that.append('<img src="path\to\image.png" />'); // add a new image 
+0

但是,如果我需要刪除圖像只有書房我會做 –

+0

然後,你可以嘗試'that.find('img')。remove()' –

+0

@ PHP_USER1如果你想用其他圖像替換該圖像那麼你可能想嘗試'replaceWith()'http://api.jquery.com/replaceWith/ –

3
var that = $(this).parent('.fpic'); 

that指向家長,而不是圖像。

和你正在做

that.remove();這將刪除fpic

你必須

that.find('img').remove();

更換圖像,你可以做

that.find('img').attr('src',srcOfAnImage);代替.remove()

+0

但是如果我需要刪除圖像只有臥室我會做 –

+0

@ PHP_USER1:檢查更新的答案 –

+0

thnks很多和如果刪除後我想更換它wid另一個圖像 –

相關問題