Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过使用javascript单击按钮在另一个DIV中显示所选图像?_Javascript_Jquery - Fatal编程技术网

如何通过使用javascript单击按钮在另一个DIV中显示所选图像?

如何通过使用javascript单击按钮在另一个DIV中显示所选图像?,javascript,jquery,Javascript,Jquery,这是密码。。实际上,映像是从repeater控件中的数据库动态填充的。我想要的是,当单击selecte template时,所选图像应该首先替换里面的空.jpg <tr> <td style="text-align: center"> <asp:Image src="../../Images/empty.jpg" style="height: 400px" ID="imgSide" ClientIDMode="Static" runat="s

这是密码。。实际上,映像是从repeater控件中的数据库动态填充的。我想要的是,当单击selecte template时,所选图像应该首先替换里面的空.jpg

<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>

试试这个

$('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);
});

您的
ChangeImage()在哪里?
?ChangeImage()是我想用javascript编写的一个函数,应该在单击按钮时调用它。。我还没有写它。
$(this)。prev()
在这种情况下,它会返回任何东西吗?@sridharr对于高效的代码,您仍然可以委托给最近的父元素而不是文档。在元素的查找过程中,委托给文档的速度要慢得多。@jai ya当然可以使用表id,但我们不知道id@SridharR:谢谢这正是我想要的。。。但当我点击按钮时,图像仍会显示,然后消失。