用于图像控件的加载客户端事件
本文关键字:客户端 事件 加载 图像 控件 用于 | 更新日期: 2023-09-27 18:31:34
我需要将客户端onLoad
事件与 ASP.Net 图像控件绑定。我已经尝试了很长时间,但没有成功。
函数名称onload="onLoadFunction(this)"
脚本:
function onLoadFunction(img) {
$(img).css("visibility", "visible"); // Using jQuery
// img.style.visibility = "visible"; // Using just javascript.
}
标记:
<asp:Image ID="imgTopFourImg2" runat="server" width="170px" height="112px" CssClass="ArticleImgHP" border="0" ImageUrl="hello.jpg" OnLoad="onLoadFunction(this)" />
这对我不起作用,如果有人可以帮助我解决这个问题,我将不胜感激。
$("img #xyz").bind("load", function () { $(this).css("visibility", "visible"); });
OnLoad 属性用于将事件处理程序 Load 事件添加,该事件是服务器端事件,而不是客户端事件。
如果要创建生成的图像元素的 onload 属性,则需要使用 属性集合
imgTopFourImg2.Attributes["onload"] = "onLoadFunction(this)";
从评论编辑
由于映像位于中继器项内,因此在代码隐藏中不可用。处理项数据绑定事件:
void R1_ItemDataBound(Object Sender, RepeaterItemEventArgs e) {
// This event is raised for the header, the footer, separators, and items.
// Execute the following logic for Items and Alternating Items.
if (e.Item.ItemType == ListItemType.Item
|| e.Item.ItemType == ListItemType.AlternatingItem)
{
var imgTopFourImg2 = e.Item.FindControl("imgTopFourImg2") as Image;
if (imgTopFourImg2 != null)
imgTopFourImg2.Attributes["onload"] = "onLoadFunction(this)";
}
}
}
$("#imgTopFourImg2").bind("load", function () { $(this).show(); });
值得研究一下show()
和hide()
方法,因为你已经在使用jQuery了。
$("img #id").bind("load", function () { $(this).css("visibility", "visible"); });