简体   繁体   English

如何在JavaScript函数中获取列表框项目引用

[英]How to get list box item reference in javascript function

I have Listview control on webform.aspx page with below defination... 我在webform.aspx页面上具有以下定义的Listview控件...

<asp:ListView runat="server" ID="dispalyProducts">
            <LayoutTemplate>
                <table runat="server" id="table1">
                    <tr runat="server" id="itemPlaceholder">
                    </tr>
                </table>
            </LayoutTemplate>
            <ItemTemplate>
                <tr id="Tr1" runat="server">
                    <td id="Td1" runat="server">
                        <%-- Data-bound content. --%>
                        <asp:Label runat="server" Text='<%#Eval("ProductName") %>' />
<br/>
                        <asp:TextBox runat="server" />
                        <br/>
                        <asp:Label runat="server" Text='<%#Eval("ProductID") %>' />
                        <br/>
                        <asp:Button runat="server" Text="Add TO cart" OnClientClick="AddToCart('<%#Eval("ProductID") %>');return false;"/>
                    </td>
                </tr>
            </ItemTemplate>
        </asp:ListView>

Whent he program runs, it creates a list of product ID, name and a button. 程序运行时,它将创建产品ID,名称和按钮的列表。

I want to use this button as "add to cart" functionality. 我想将此按钮用作“添加到购物车”功能。 so when a user clicks on button, i want to call a javascript function with productID, and textbox value (as item id and quantity). 因此,当用户单击按钮时,我想使用productID和文本框值(作为项目ID和数量)调用JavaScript函数。

How can I pass these values to javascript function in listview. 如何将这些值传递给ListView中的javascript函数。

<asp:Button ... OnClientClick='AddToCart(\"<%#Eval("ProductID") %>\", \"<%#Eval("ProductName") %>\");return false;'/>

您可以将值作为参数传递给js函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在列表框中获取所选项的索引? - How to get the index of the selected item in a list box? 如何使用Javascript获取选定的列表项? - How to get a selected list item using Javascript? 如何在 JavaScript 中获取随机列表项 - How to get a random list item in JavaScript 如何获取列表项 Javascript 的值/文本 - How to get Value / Text of a List item Javascript 在Jquery中选择后如何获取列表框项目文本? - How to get the list box item text once it selected in Jquery? 如何在引导程序下拉列表的标题中显示所选项目? 以及如何在JavaScript警报框中显示所选项目? - How to display selected item in the title of the bootstrap dropdown list ? and how to display selected item on a javascript alert box? Javascript选择器:引用子函数中的选定项 - Javascript selectors: reference selected item in child function 如何使用JavaScript获取列表项中的第一个和最后一个元素 - How to get first and last element in list item using javascript jQuery / Javascript:如何获取匿名函数以引用外部变量? - jQuery/Javascript: How to get anonymous function to reference variable declare outside? Sencha touch 2如何在视图中引用列表项? - Sencha touch 2 how to reference to a list item with in view?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM