我有一个asp.net文本框:
<asp:TextBox runat="server" id="tb" ToolTip="A" />.
我需要能够根据从下拉列表中选择的值设置工具提示。
If (var == "something") {
ToolTip = "B";
} else {
ToolTip = "A";
}
我根据DropDown的默认值将ToolTip设置为初始值。当它改变时,我需要设置工具提示。
我已经从网上看过并尝试过多种解决方案,但却无法让它们发挥作用。
我正在使用VS 2008和IE7,该网站使用的是VS服务器,而不是IIs。我已经验证我有正确的字段,并且可以使用调试器更改'title'。
提前谢谢
答案 0 :(得分:2)
我试过这样:
<asp:TextBox runat="server" ID='txtSomething' ToolTip='Some tooltip' CssClass='myTextBox'></asp:TextBox>
在我的jQuery中,我写道:
$(function () {
var maybe = true;
if (maybe) {
$('.myTextBox').attr('title', 'Some other tooltip');
}
});
渲染时我的文本框显示“其他工具提示”作为标题
答案 1 :(得分:0)
使用jQuery这样的东西:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#<%=DropDownList1.ClientID %>").change(function () {
var tooltip = "B";
var val = $(this).val();
if (val == "One") {
tooltip = "A";
}
$("#<%=TextBox1.ClientID %>").attr('title', tooltip);
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="One" />
<asp:ListItem Text="Two" />
<asp:ListItem Text="Three" />
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server" ToolTip="A"></asp:TextBox>
</form>
</body>
</html>
更新 - 类选择器方式:
$(function () {
$('.myddl').change(function () {
var tooltip = "B";
var val = $(this).val();
if (val == "One") {
tooltip = "A";
}
$('.mytb').attr('title', tooltip);
});
});
<asp:DropDownList ID="DropDownList1" runat="server" CssClass="myddl">
<asp:TextBox ID="TextBox1" runat="server" ToolTip="A" CssClass="mytb"></asp:TextBox>
答案 2 :(得分:0)
我在我的问题中列出的代码有效并且确实更改了工具提示。问题出在于创建网站的人以及他对CSS和Javascript / JQuery / Json的阴谋;不知何故,访问工具提示的能力被禁用。