从xml列表填充的asp下拉列表如何添加工具提示

时间:2012-06-06 16:06:11

标签: javascript asp.net drop-down-menu tooltip

请帮助我做错了什么?

我有一个xml格式的国家/地区,格式为

 <COUNTRY value="blah" title="blah">blah blah</COUNTRY>

我有一个asp下拉列表,其中包含广泛的xml列表和dropdownlist html格式:

<asp:DropDownList ID="mCOUNTRY" runat="server" Width="205"      onmouseover="showHideTooltip()"> </asp:DropDownList>

----- showHideTooltip()下面-----

<script language="JavaScript">

function showHideTooltip() 
{
var obj = document.getElementById("mCOUNTRY");
obj.title[obj.selectedIndex].title;
}

</SCRIPT>
</CODE> 

2 个答案:

答案 0 :(得分:3)

鼠标悬停事件使用C#示例显示工具提示下拉列表项 使用C#在示例中使用鼠标悬停事件在Asp.net下拉列表项中使用工具提示: http://asp-net-by-parijat.blogspot.in/2014/08/show-tooltip-dropdownlist-items-by.html

答案 1 :(得分:1)

您可能希望在show/hide tooltips with jQuery上查看此帖子,您可以改编自此SO answer或此SO answer

认为你需要做这样的事情:

<div id="tooltip" style="display:none;">Content will go here</div>
<asp:DropDownList ID="mCOUNTRY" runat="server" Width="205" 
onmouseover="showTooltip()" onmouseout="hide()"> </asp:DropDownList>

用这个用于javascript

<script language="JavaScript">
function showTooltip() {
  var obj = document.getElementById("mCOUNTRY");
  var title = obj.title[obj.selectedIndex].title;
  var tooltip = document.getElementById("tooltip");
  tooltip.innerHtml = title;
  tooltip.style.visibility = 'visible';
  tooltip.style.left = event.screenX + 'px';
  tooltip.style.top = event.screenY + 'px';
}

function hideTooltip(){
  document.getElementById("tooltip").style.visibility = 'hidden';
}
</script>

jQuery解决方案(如上所述,虽然会更优雅)

相关问题