更新:
现在的问题是在使用firebug后我发现第一个元素获取title属性而其他元素没有,并且在任何链接上悬停后,第一个链接的title属性消失了任何想法?
当我点击这样的链接时,我打开了哪个页面:
<a class="pictures" href="#" onClick="MM_openBrWindow('content_image.php','images','menubar=yes,scrollbars=yes,resizable=yes,width=650,height=700')" title="Images"></a>
此页面的图像存储在文件夹中:
$open = opendir($path);
while($images = readdir($open)){
if ($images != "." && $images != "..") {
$allimages[] = $images;
}
}
foreach($allimages as $val){
?>
<div class="uploaded_image"><img src="../content_img/<?php echo $val; ?>" align='middle' width='150px' height='100px'>
<form><a href="#" title="<?php echo $val; ?>" class="del_img"><img src="images/delete.gif"/></a> <textarea name='text_area' rows=1 cols=20 >../content_img/<?php echo $val; ?></textarea> <input type='button' value='select path' onClick='javascript:this.form.text_area.focus();this.form.text_area.select();'> Copy path and paste in image path field </form></div>
<?php
}
closedir($open);
?>
我正在尝试使用href
的常规链接删除带有以下属性的页面:
?do=delete&img=<?php echo $val; ?>
然后unlink()
图片。但是,只要我将鼠标悬停在链接上而不点击,图像就会被删除。我不知道为什么。
我尝试使用AJAX:
$(document).ready(function(e) {
$("div.uploaded_image").on("click","a.del_img",function(e){
e.preventDefault();
var img = $(this).attr("title");
var qst = "?img="+img+"&path=content_img";
var ajax = false;
ajax = new XMLHttpRequest();
ajax.open("post","del_image.php"+qst);
ajax.onreadystatechange = function(){
if(ajax.readyState == 4 && ajax.status == 200){
}
}
ajax.send(null);
setTimeout(ref,1500);
});
});
function ref(){
window.location = "content_image.php"
}
这个PHP代码工作使用AJAX删除:
$img = $_REQUEST['img'];
$path = $_REQUEST['path'];
unlink("../".$path."/".$img);
当我第一次点击删除链接时,它不起作用。我必须再次点击删除图像。有什么帮助吗?
答案 0 :(得分:1)
$open = opendir($path);
while($images = readdir($open)){
if ($images != "." && $images != "..") {
$allimages[] = $images;
}
}
foreach($allimages as $val){
?>
<div class="uploaded_image"><img src="../content_img/<?php echo $val; ?>" align='middle' width='150px' height='100px'>
<form><a href="Javascript:void(0);" title="<?php echo $val; ?>" class="del_img"><img src="images/delete.gif"/></a> <textarea name='text_area' rows=1 cols=20 >../content_img/<?php echo $val; ?></textarea> <input type='button' value='select path' onClick='javascript:this.form.text_area.focus();this.form.text_area.select();'> Copy path and paste in image path field </form></div>
<?php
}
closedir($open);
?>
用此代码替换代码
答案 1 :(得分:0)
变化
$("div.uploaded_image").on("click","a.del_img",function(e){
e.preventDefault();
到
$("div.uploaded_image a").click(function(e){
e.preventDefault();
...