asp.net给DropDownList添加ToolTip(title)属性
/// <summary>
/// 为DropDownList的Item加title属性
/// </summary>
/// <param name="ddl">DropDownList</param>
private void addTitle(DropDownList ddl)
{
foreach (ListItem item in ddl.Items)
{
item.Attributes.Add("title", item.Text);
}
}
/// 为DropDownList的Item加title属性
/// </summary>
/// <param name="ddl">DropDownList</param>
private void addTitle(DropDownList ddl)
{
foreach (ListItem item in ddl.Items)
{
item.Attributes.Add("title", item.Text);
}
}
<script language="javascript" type="text/javascript">
function showdropitem()//给页面全部select加title属性
{
var el = document.getElementsByTagName("select");
for(i=0;i<el.length;i++)
{
showitem(el[i]);
}
}
function showitem(obj)//将就需要加title属性的select传进来
{
for(j=0;j<obj.options.length;j++)
{
obj.options[j].title = obj.options[j].text;
}
}
</script>
function showdropitem()//给页面全部select加title属性
{
var el = document.getElementsByTagName("select");
for(i=0;i<el.length;i++)
{
showitem(el[i]);
}
}
function showitem(obj)//将就需要加title属性的select传进来
{
for(j=0;j<obj.options.length;j++)
{
obj.options[j].title = obj.options[j].text;
}
}
</script>