0

我创建了一个切换按钮,它通过 4 个状态在单个按钮上切换!

切换按钮位于 GridView 中,而 GridView 又嵌套在 FormView 中。该按钮在 HTML 页面中运行良好,并在选择 4 个图像中的每一个时根据需要将值提交到文本框中。但是在 GridView 中它不起作用!任何人都可以提供帮助或者我应该知道任何已知问题吗?

<script type="text/javascript">
   $(document).ready(function() {
     $(".imageButton").ready(function() {
           $("img").click(function() {
               if ($(this).attr("src") == "../../../images/tick_50.png") {
                    $(this).attr("src", '../../../images/excl_mark_50.png'); //orange image
                     $(this).parent().siblings("input").attr("value", '2');
                 } else if ($(this).attr("src") == "../../../images/excl_mark_50.png") {
                     $(this).attr("src", '../../../images/cross_50.png'); //red image
                     $(this).parent().siblings("input").attr("value", '3');
                 } else if ($(this).attr("src") == "../../../images/cross_50.png") {
                     $(this).attr("src", '../../../images/absent_50.png'); //blue image
                     $(this).parent().siblings("input").attr("value", '4');
                 } else if ($(this).attr("src") == "../../../images/absent_50.png") {
                     $(this).attr("src", '../../../images/tick_50.png'); //green image
                     $(this).parent().siblings("input").attr("value", "1");
                }
           });
     });

});
</script>



<asp:FormView ID="FormView1" runat="server" DataSourceId="SqlDataSource1"
                DataKeyNames="tt_id,s_id,n_id,o_id" AllowPaging="false">

   <ItemTemplate>

                    <br />

  <asp:UpdatePanel ID="UpdatePanel2" runat="server">
   <ContentTemplate>
    <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False"
        CssClass="rounded-corner" DataKeyNames="tt_id,s_id,n_id,o_id" 
           ShowFooter="True" >
        <Columns>



            <asp:TemplateField HeaderText="Results" SortExpression="outcome" HeaderStyle-Font-Bold="true" >
                <EditItemTemplate >
                <div class="imageButton"><a href="#"> <asp:Image ID="imgStatusEdit" runat="server" ImageURL='<%# GetImage(CType(Eval("o_id"),Integer)) %>' /></a>
                    <asp:TextBox ID="txtOutcome" runat="server"></asp:TextBox></div>





                </EditItemTemplate>
                <ItemTemplate>
     <asp:Image ID="imgStatus" runat="server" ImageURL='<%# GetImage(CType(Eval("o_id"),Integer)) %>' />
                    <%--<asp:Label ID="Label2" runat="server" Text='<%# Bind("o_id") %>'></asp:Label>--%>

                </ItemTemplate>
                <HeaderStyle Font-Bold="True" />
                <ItemStyle Width="67px" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Notes" SortExpression="notes" ItemStyle-Width="" HeaderStyle-Font-Bold="true">
                <EditItemTemplate>
                    <asp:TextBox ID="txtNotes" runat="server" TextMode="MultiLine" Text='<%#Eval("notes")%>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("notes")%>'></asp:Label>
                </ItemTemplate>
                <HeaderStyle Font-Bold="True" />
            </asp:TemplateField>
            <asp:CommandField ButtonType="Link" UpdateText="Update" CancelText="Cancel" 
                EditText="Edit" ShowEditButton="True" />
        </Columns>


    </asp:GridView>               
      </ContentTemplate>
    </asp:UpdatePanel>              
             </ItemTemplate>
</asp:FormView>
4

1 回答 1

0
$(document).ready(function () {
            $('.imageButton').find('img').on('click', function () {
                if ($(this).attr('src') == '../../../images/tick_50.png') {
                    $(this).attr('src', '../../../images/excl_mark_50.png'); //orange image
                    $(this).parents('.imageButton').find('input').val('2');
                } else if ($(this).attr('src') == '../../../images/excl_mark_50.png') {
                    $(this).attr('src', '../../../images/cross_50.png'); //red image
                    $(this).parents('.imageButton').find('input').val('3');
                } else if ($(this).attr('src') == '../../../images/cross_50.png') {
                    $(this).attr('src', '../../../images/absent_50.png'); //blue image
                    $(this).parents('.imageButton').find('input').val('4');
                } else if ($(this).attr('src') == '../../../images/absent_50.png') {
                    $(this).attr('src', '../../../images/tick_50.png'); //green image
                    $(this).parents('.imageButton').find('input').val('1');
                }
            });
        });
于 2012-05-10T11:50:11.180 回答