简体   繁体   中英

How to create javascript call dynamically in c# , .asp.net

net , c#. I am calling a javascript by using following code . `

<script type="text/javascript">
    $(function () {

       $("[src='/pinterest/portals/0/Images/about-person3.jpg']").pinit();
       $("[src='/pinterest/portals/0/Images/about-us-group.jpg']").pinit();
    });
    </script>

My c# code is

<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<br />
<img ID="ImageZoom" runat="server" src='<%# DataBinder.Eval(Container.DataItem, "ImageUrl") %> '  style="display: inline; height:auto; left: 0pt; top: 0pt; width:auto;" />
    <asp:CheckBox ID="CheckBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ImageId") %> '  /> 

</ItemTemplate>
</asp:Repeater>`

if i add more images i should call javascript for all images .

You're question is vague at best, but I think this is what you're looking for:

  1. Assign a class to the images that you want to call pinit() on.
  2. Use jQuery's class selector to retrieve the appropriate objects.

     <img ID="ImageZoom" class='pinitPlease' runat="server" ... /> $(function () { $(".pinitPlease").pinit(); }); 

assuming you want to zoom images that are located in /pinterest/portals/0/Images/

you can adapt your jquery selector to select those imgages that start with that path

$("[src^='/pinterest/portals/0/Images/']").pinit();

您所有的图像ID中都将带有“ ImageZoom”一词,因此您可以以此作为选择器,然后一起查找所有图像。

$("[id*='ImageZoom']").pinit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM