当前位置:编程学习 > C#/ASP.NET >>

找位大哥教我下这个问题

<asp:DropDownList class="smallselect" onchange=" return setColor();"
id="DropDownList2"runat="server">
<asp:ListItem style="COLOR: #ff0000" value="red" selected>红色</asp:ListItem>
<asp:ListItem style="COLOR: #ffa500" value="orager">橙色</asp:ListItem>
<asp:ListItem style="COLOR: #ffff00" value="yellow">黄色</asp:ListItem>
<asp:ListItem style="COLOR: #008000" value="green">绿色</asp:ListItem>
<asp:ListItem style="COLOR: #32cd32" value="cyan">青色</asp:ListItem>
<asp:ListItem style="COLOR: #0000ff" value="blue">蓝色</asp:ListItem>
<asp:ListItem style="COLOR: #800080" value="purple">紫色</asp:ListItem>
</asp:DropDownList>

<SCRIPT>
var messageColor='red';
function setColor()
{
  var selectColor = document.getElementById('selectColor');
  messageColor=selectColor.value;
}
</SCRIPT>

这是一个下拉列表框 我的问题是如果采用服务器控件 点击下拉列表时显示的字上出颜色,可是为什么我有web控件则怎么调都没有字体上的颜色 请个高手指点下 本人用.net 2003做的 先说谢谢了 --------------------编程问答-------------------- 你将问题说清楚一点,你的意思是下列列表没有表现颜色样式还是无法获取已选择项的值? --------------------编程问答--------------------
 给个方法:
  for (int i = 0; i < DropDownList1.Items.Count; i++)
                {
                    if (i % 2 == 0)
                    {
                        DropDownList1.Items[i].Attributes.Add("style","BACKGROUND-COLOR:#008888");
                    }
                } --------------------编程问答-------------------- 我是说下拉列表里面的选项上的字体颜色 --------------------编程问答-------------------- 哪里不行,你看看.
另外,楼主说的WEB控件是HTML控件吧?!好象规范的说法是"HTML控件"吧,有没有看到这个System.Web.UI.HtmlControls;
        <select>
            <option style="COLOR: #ff0000" value="red"> 红色 </option>
            <option style="COLOR: #ffa500" value="orager"> 橙色 </option>
            <option style="COLOR: #ffff00" value="yellow"> 黄色 </option>
            <option style="COLOR: #008000" value="green"> 绿色 </option>
            <option style="COLOR: #32cd32" value="cyan"> 青色 </option>
            <option style="COLOR: #0000ff" value="blue"> 蓝色 </option>
            <option style="COLOR: #800080" value="purple"> 紫色 </option>
        </select>    
--------------------编程问答-------------------- 你这种形式是可以的 我要的服务器控件啊  象我上面的那样 可能上面是打字打快了 说错了点 --------------------编程问答-------------------- 一样没有问题,我不知道你的代码是错了还是发贴时格式被打乱,你COPY我的试试
<asp:DropDownList   class="smallselect"   onchange="   return   setColor();" id="DropDownList2" runat="server">
    <asp:ListItem   style="COLOR:   #ff0000"   value="red"   selected> 红色 </asp:ListItem>
    <asp:ListItem   style="COLOR:   #ffa500"   value="orager"> 橙色 </asp:ListItem>
    <asp:ListItem   style="COLOR:   #ffff00"   value="yellow"> 黄色 </asp:ListItem>
    <asp:ListItem   style="COLOR:   #008000"   value="green"> 绿色 </asp:ListItem>
    <asp:ListItem   style="COLOR:   #32cd32"   value="cyan"> 青色 </asp:ListItem>
    <asp:ListItem   style="COLOR:   #0000ff"   value="blue"> 蓝色 </asp:ListItem>
    <asp:ListItem   style="COLOR:   #800080"   value="purple"> 紫色 </asp:ListItem>
</asp:DropDownList> 
--------------------编程问答-------------------- 如果你用的是用户控件来做的话,id 信息是会变换的 --------------------编程问答-------------------- 我也是那样想的 可是我运行 看不到效果 烦糙 一个这样的小事做了2个小时还没做出来 --------------------编程问答-------------------- 6楼的代码楼主测试没有效果?! --------------------编程问答-------------------- hehe  --------------------编程问答-------------------- <%@ Page language="c#" Codebehind="chat_input.aspx.cs" AutoEventWireup="false" Inherits="OA_Office.table_index.files.chat.chat_input" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
   <HEAD>
     <TITLE></TITLE>
        <LINK href="style.css" type="text/css" rel="stylesheet">
        <META content="C#" name="CODE_LANGUAGE">
<META content="JavaScript" name="vs_defaultClientScript">
<META content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.3199" name="GENERATOR">
   </HEAD>
<BODY class="bodycolor" leftMargin="0" topMargin="0" rightMargin="0">
   <FORM id="Form1" name="Form1" method="post" runat="server">
     <SCRIPT src="images/prototype.ashx" type="text/javascript"></SCRIPT>
     <SCRIPT src="images/core.ashx" type="text/javascript"></SCRIPT>
     <SCRIPT src="images/converter.ashx" type="text/javascript"></SCRIPT>
     <SCRIPTsrc="images/AnyOffice.general.netmeeting.attend.AjaxMethods,
               AnyOffice.ashx"type="text/javascript"></SCRIPT>
     <TABLE class="small" cellSpacing="1" cellPadding="3" width="101%" bgColor="#000000" border="0">
     <TBODY>
<TR class="TableHeader">
   <TD><SPAN>对象
      <asp:DropDownList class="SmallSelect" id="DropDownList1" runat="server"></asp:DropDownList>
悄悄话
     <INPUT id="IsPrivate" type="checkbox" value="checkbox" name="IsPrivate">
         字色
     <asp:DropDownList class="smallselect" onchange=" return setColor();" id="DropDownList2" runat="server">
     <asp:ListItem style="COLOR: #ff0000" value="red" selected>红色</asp:ListItem>
     <asp:ListItem style="COLOR: #ffa500" value="orager">橙色</asp:ListItem>
     <asp:ListItem style="COLOR: #ffff00" value="yellow">黄色</asp:ListItem>
     <asp:ListItem style="COLOR: #008000" value="green">绿色</asp:ListItem>
     <asp:ListItem style="COLOR: #32cd32" value="cyan">青色</asp:ListItem>
     <asp:ListItem style="COLOR: #0000ff" value="blue">蓝色</asp:ListItem>
     <asp:ListItem style="COLOR: #800080" value="purple">紫色</asp:ListItem>
     </asp:DropDownList>
    <SCRIPT>
      var messageColor='red';

  function setColor()
   {
   var selectColor = document.getElementById('selectColor');
   messageColor=selectColor.value;
   }
     </SCRIPT>就是这里 请大家在看看有没有外面把里面的颜色覆盖的地方
自动滚动<INPUT id="chScroll" type="checkbox" CHECKED name="chScroll"> </SPAN>
</TD>
</TR>
<TR class="TableHeader">
<TD height="30">
<asp:TextBox class="SmallInput" id="TextBox1" runat="server" MaxLength="100" Width="500px"></asp:TextBox>
<asp:Button class="SmallButton" id="Button1" runat="server" Text="发言"></asp:Button>
</TD>
</TR>
</TBODY>
</TABLE>
<SCRIPT language="javascript">
//回车键发送消息
function clickButton(e, buttonid)

var bt = document.getElementById(buttonid); 
if (typeof bt == 'object')

if(navigator.appName.indexOf("Netscape")>(-1)){ 
if (e.keyCode == 13)

bt.click(); 
return false; 


if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))

if (event.keyCode == 13)

bt.click(); 
return false; 


}  


function GetUsers()
{
if(timer_user!=null)
window.clearTimeout(timer_user);

AnyOffice.general.netmeeting.attend.AjaxMethods.GetOnline(1,CallBack_GetUsers);
timer_user=setTimeout("GetUsers()",30000);
}

function SayTo(userId)
{
var oSelect = document.getElementById("selectOnlineUsers");
for(var i=0;i<oSelect.length;i++)
{
if(oSelect.options[i].value == userId)
{
oSelect.options[i].selected = true;
}
}

}

function CallBack_GetUsers(res)
{
if(res != null && res.value != null && res.value.Tables != 0 && res.value.Tables.length == 1)
{
var selectValue="";
var usersList="";
var onlineNums=0;
var opt;
var oSelect = document.getElementById("selectOnlineUsers");
selectValue = oSelect.value;

// clear dropdownlist
for(var i=oSelect.length-1; i>0; i--)
{
oSelect.options[i] = null;
}

for(var i=0; i<res.value.Tables[0].Rows.length; i++)
{
usersList += "<a href=\"javascript:parent.chat_input.SayTo('" + res.value.Tables[0].Rows[i].UserId + "');\">" + res.value.Tables[0].Rows[i].NickName + "</a><br>"
opt = new Option(res.value.Tables[0].Rows[i].NickName, res.value.Tables[0].Rows[i].UserId);
oSelect.options[oSelect.length] = opt;
onlineNums +=1;
}

var oOnlineNums = parent.chat_user.document.getElementById("onlineNums")
if(oOnlineNums != null)
oOnlineNums.innerHTML = "在线人员" + onlineNums + "人";

var onlineUsersList = parent.chat_user.document.getElementById("onlineUsersList")
if(onlineUsersList != null)
onlineUsersList.innerHTML = usersList;


for(var i=0;i<oSelect.length;i++)
{
if(oSelect.options[i].value == selectValue)
{
oSelect.options[i].selected = true;
}
}

}
}

function SendMessage()
{
var color = messageColor;
var content = document.getElementById('txtMsg').value;
if(content == "")
return;
var oSelect = document.getElementById("selectOnlineUsers");
var toId = oSelect.value;

var isPrivate = document.all.IsPrivate.checked;

//输入框清空
document.getElementById('txtMsg').value='';

AnyOffice.general.netmeeting.attend.AjaxMethods.SendMessage(1, toId, color, isPrivate, content);
}

GetMessage();
GetUsers();

</SCRIPT>
</FORM>
</BODY>
</HTML>
--------------------编程问答-------------------- 我把全部复制出来了 --------------------编程问答-------------------- 我将你在11楼贴出的代码COPY到网页,很郑重的告诉你,效果跟我期望的一样,下列列表项字体颜色跟设置的一样,red,blue,black,cyan.....
我想,你新建一个网页试试看。
另外,你既已声明<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.0   Transitional//EN">,最就按这个标准,尽量不要在HTML里出现不规范的字符,如大小写,属性等。 --------------------编程问答-------------------- 哦 我试试  谢谢你的意见 --------------------编程问答-------------------- 你的意思是当点击某个功能时,那个连接就会变色吧
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,