如何在asp.net中动态创建的div上调用javascript函数 [英] how to call a javascript function on dynamic created div in asp.net
本文介绍了如何在asp.net中动态创建的div上调用javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在div的mouseover上调用javascript函数,div在asp.net中动态创建。我的代码是:
how to call a javascript function on mouseover of div, the div is dynamically created in asp.net. my code is:
strRet.Append("<div class='col_1_of_3 span_1_of_3 tryathome-container'>")
strRet.Append("<div class='inner_content clearfix'>")
strRet.Append("<div class='product_image'>")
strRet.Append("<a class='product-image' href='productdetails.aspx?id=" & encrPvCode & "&url=productlist.aspx?" & IIf(String.IsNullOrWhiteSpace(cid), "", "id=" & encrCatId) & IIf(String.IsNullOrWhiteSpace(pid), "", "&pid=" & encrPvCode) & "'>")
strRet.Append("<input type='hidden' id='hdnPvCode" & i.ToString & "' value='" & PvCode & "'/>")
strRet.Append("<img src='" & imgSrc & "' alt='' />")
strRet.Append("</a>")
strRet.Append("<div class='product_hover_option'>")
i想要在
i want to call the alert on
请建议我代码,如何以及在哪里可以编写该代码。
提前感谢
please suggest me code, how and where can i write that code.
thanks in advance
推荐答案
在您将div字符串附加到页面之前,在javascript(On Page)中定义鼠标悬停功能。
Define your mouse over function in javascript(On Page) before you are going to append your div string into page.
function myMouseMover()
{
alert('Mouse Over');
}
附加字符串只需将onmouseover属性添加到div中,如下所示。
while appending string just add the onmouseover attribute to you div as below.
strRet.Append("<div class="col_1_of_3 span_1_of_3 tryathome-container" onmouseover="myMouseover()">")</div>
这篇关于如何在asp.net中动态创建的div上调用javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文