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 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献