<script type="text/javascript">
$(function () {
$("#divSCA img").click(function () {
var name = $(this).attr("alt");
$.ajax({
url: "delimg.aspx",
data: "picname=" + name,
datatype: "json",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function (data, textStatus) {
alert(data.result);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest);
}
});
});
});
</script>
<body>
<div id="divSCA">
<img src="Images/xiyangyang1.jpg" alt="xiyangyang1.jpg" />
<a >删除</a>
< img src="Images/xiyangyang2.jpg" alt="xiyangyang2.jpg" />
<a >删除</a> </div>
</body>这个怎么改成点击按钮或其他事件呢?
我想要的结果是:<a >删除</a> 按这里的删除就调用这个事件,而不是点击图片就执行,这个方法怎么改呢?
$(function () {
$("#divSCA img").click(function () {
var name = $(this).attr("alt");
$.ajax({
url: "delimg.aspx",
data: "picname=" + name,
datatype: "json",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function (data, textStatus) {
alert(data.result);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest);
}
});
});
});
</script>
<body>
<div id="divSCA">
<img src="Images/xiyangyang1.jpg" alt="xiyangyang1.jpg" />
<a >删除</a>
< img src="Images/xiyangyang2.jpg" alt="xiyangyang2.jpg" />
<a >删除</a> </div>
</body>这个怎么改成点击按钮或其他事件呢?
我想要的结果是:<a >删除</a> 按这里的删除就调用这个事件,而不是点击图片就执行,这个方法怎么改呢?
$(this).prev("img")///执行
})
var name = $(this).prev("img").attr("alt");
这样呢
的话,点<a >删除</a> 就不起作用了
应该是$("#divSCA a").click(function () {
var name = $(this).prev("img").attr("alt");
var name = $(this).prev("img").attr("alt");这样写,报:
undefinde求救
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(function () {
$("#divSCA a").click(function () {
var name = $(this).prev("img").attr("alt");
$.ajax({
url: "delimg.aspx",
data: "picname=" + name,
datatype: "json",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function (data, textStatus) {
alert(data.result);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest);
}
});
});
});
</script>
</head>
<body>
<div id="divSCA">
<img src="Images/1.jpg" alt="xiyangyang1.jpg" />
<a>删除</a>
<img src="Images/1.jpg" alt="xiyangyang2.jpg" />
<a>删除</a>
</div>
</body>
</html>测试结果和你的源码一样
#divSCA
{
position: absolute;
width: 700px;
height: 500px;
font-size: 12px;
background: #fff;
border: 0px solid #000;
z-index: 10001;
display: none;
overflow:auto;
}
</style>
<script type="text/javascript">
$(function () {
$("#divSCA a").click(function () {
var name = $(this).prev("img").attr("alt");
alert(name);
$.ajax({
url: "delimg.aspx",
data: "picname=" + name,
datatype: "json",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function (data, textStatus) {
alert(data.result);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest);
}
});
});
});
</script><div id="divSCA">
<a href="KunLunUpFile.html">上传图片</a> <input type="button" value="关闭" onclick="closeDiv()" />
<asp:DataList ID="DataList1" runat="server" RepeatColumns="4"
DataKeyField="Name">
<ItemTemplate>
<a href="#" onclick="SetTextChanged('<%#Eval("Name")%>')">
<img alt="<%#Eval("Name")%>" height="70" width="70" src='<%#"../../UFile/" +Eval("Name")%>' />
<%--<asp:image ID="Image1" runat="server" Height="70" width="70" ImageUrl='<%#"../../UFile/" +Eval("Name")%>'/>--%>
<br/><%#Eval("Name")%>
</a>
<a>删除</a>
</ItemTemplate>
</asp:DataList>
</div>
我的就是拿不到值 ..........
alert(name);
这里拿不到图片的alt 值
肯定拿不到。。
试试这个
这个可以谢了