TonyGJY 2018-10-17 09:33 采纳率: 33.3%
浏览 1615

如何用ASP.NET中的RadioButton、RadioButtonList、CheckBox和CheckBoxList控件动态地改变字体的颜色

我目前做了很简单的一步,就是列出了四种控件。。属于脑残行为。那么我该怎么做添加代码才能实现题目中的功能呢?

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="4.aspx.cs" Inherits="动态地改变字体显示效果._4" %>

<!DOCTYPE html>









    <asp:RadioButtonList ID="RadioButtonList1" runat="server">

    </asp:RadioButtonList>

    <asp:CheckBox ID="CheckBox1" runat="server" />

    <asp:CheckBoxList ID="CheckBoxList1" runat="server">                </asp:CheckBoxList>
    </div>

</form>


  • 写回答

1条回答 默认 最新

  • threenewbee 2018-10-17 16:35
    关注

    给你写了一个

     <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
        CodeBehind="Default.aspx.cs" Inherits="Q702913._Default" %>
    
    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
        <h2>
            Welcome to ASP.NET!
        </h2>
        <p>
            To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
        </p>
        <p>
            You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409"
                title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
        </p>
        <asp:RadioButtonList ID="RadioButtonList1" runat="server"
            onselectedindexchanged="RadioButtonList1_SelectedIndexChanged" 
            AutoPostBack="True">
            <asp:ListItem>red</asp:ListItem>
            <asp:ListItem>blue</asp:ListItem>
            <asp:ListItem>black</asp:ListItem>
        </asp:RadioButtonList>
        <script type="text/javascript">
            var para = document.getElementsByTagName("p");
            for (var i = 0; i < para.length; i++) {
                para[i].setAttribute("style", "color:<% =bgcolor %>");
            }
        </script>
    </asp:Content>
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace Q702913
    {
        public partial class _Default : System.Web.UI.Page
        {
            public string bgcolor = "red";
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack && RadioButtonList1.SelectedValue != "")
                {
                    bgcolor = RadioButtonList1.SelectedValue;
                }
            }
    
            protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
            {
                bgcolor = RadioButtonList1.SelectedValue;
            }
        }
    }
    
    
    
    
    

    图片说明

    代码下载:https://download.csdn.net/download/caozhy/10728187

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料