简体   繁体   中英

How to show selected image in another DIV by clicking on a button using javascript?

This is the code.. actually the images are populated in dynamically from database in repeater control. what i want is when clicked on selecte template, the selected image should replace the empty.jpg inside first <td> .

<tr>
    <td style="text-align: center">
        <asp:Image src="../../Images/empty.jpg" style="height: 400px" ID="imgSide" ClientIDMode="Static" runat="server"/></td>
    <td>
        <div class="row-fluid">
            <ul class="thumbnails" style="list-style: none">
                <asp:Repeater ID="rptTemplates" runat="server">
                    <ItemTemplate>
                        <li class="span4">
                            <article class="thumbnail">

                                <asp:Image runat="server" ImageUrl='<%#string.Format("{0}/{1}",ConfigurationManager.AppSettings["GetTemplates"],Eval("TemplateName")) %>' />
                                <div>
                                    <asp:Button runat="server" ID="btnSelectTemplate" Text="Select Template" Style="text-align: center" ClientIDMode="Static" OnClientClick="ChangeImage('<%#string.Format("{0}/{1}",ConfigurationManager.AppSettings["GetTemplates"],Eval("TemplateName")) %>')"/>
                                </div>

                            </article>

                        </li>

                    </ItemTemplate>
                </asp:Repeater>
            </ul>
        </div>
    </td>
</tr>

Try this

$('table').on('click','.thumbnail button',function(){
 var i_url=$(this).closest('.thumbnail').find('img').attr('src');
 $(this).parents('tr').find('td:eq(0) img').attr('src',i_url);
});

DEMO

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