【发布时间】:2016-04-07 19:54:57
【问题描述】:
我正在使用 Bootstrap v3.3.5 和 JQuery v1.11.3。
I have a select list that when a value is selected, I would like the placement and css class of a tooltip to change.
我搜索了 Google & SO 并阅读了许多 SO 帖子,但我所做的许多尝试都失败了。例如,this 对我不起作用。
这是我的html代码:
<select id="id_cover_letter_type" name="cover_letter_type">
<option value="0" selected="selected">I will write my own data</option>
<option value="1">Standard Cover Letter</option>
....
</select>
<i id="id_icon_id_cover_letter_details_second_paragraph" class="fa fa-lightbulb-o blue_color icon_size26 verticalAlignTop" data-original-title="" title="" aria-describedby="tooltip229278"></i>
这是我的 jquery 代码:
我已将我为更改工具提示的数据放置(取自其他帖子)所做的已注释掉的尝试包括在内,但这些尝试对我不起作用。
$("#id_icon_id_cover_letter_details_second_paragraph").tooltip({'html': true, 'placement': 'bottom', 'title': '{% trans "Paragraph 2" %} <br /><br /> {% trans "This should detail why you want the job." %} <br /><br /> {% trans "Explain how your qualifications and career plan match the advertised position." %} <br /><br /> {% trans "The details you provide here should display that you have researched the employer, what the employer and industry are seeking and that you understand what the job requires." %}'});
if ( $('#id_cover_letter_type').val() == '0' ) {
// the following code did not work.
//$('#id_icon_id_cover_letter_details_second_paragraph').data('bs.tooltip').options.placement = 'left';
// the following code did not work.
//$('#id_icon_id_cover_letter_details_second_paragraph').tooltip({ placement: 'left' });
// the following, destroying, appling the placement and then showing the tooltip did not work.
//$('#id_icon_id_cover_letter_details_second_paragraph').tooltip('destroy');
//$("#id_icon_id_cover_letter_details_second_paragraph").tooltip({'placement':'left'});
//$("#id_icon_id_cover_letter_details_second_paragraph").tooltip('show');
// applying the placement and the showing the tooltip did not work.
//$("#id_icon_id_cover_letter_details_second_paragraph").tooltip({placement : 'left'}).tooltip('show');
} else {
// the following code did not work.
//$('#id_icon_id_cover_letter_details_second_paragraph').data('bs.tooltip').options.placement = 'bottom';
// the following code did not work.
//$('#id_icon_id_cover_letter_details_second_paragraph').tooltip({ placement: 'bottom' });
// the following, destroying, appling the placement and then showing the tooltip did not work.
//$('#id_icon_id_cover_letter_details_second_paragraph').tooltip('destroy');
//$("#id_icon_id_cover_letter_details_second_paragraph").tooltip({'placement':'bottom'});
//$("#id_icon_id_cover_letter_details_second_paragraph").tooltip('show');
// applying the placement and the showing the tooltip did not work.
//$("#id_icon_id_cover_letter_details_second_paragraph").tooltip({placement : 'bottom'}).tooltip('show');
}
另外,如果有人能告诉我将工具提示的 css 更改为类名custom-tooltip-styling123 的答案,那就太好了。
编辑
这是jsfiddle。这只是我的第二把小提琴,我不知道如何在引导程序中添加以显示工具提示。
【问题讨论】:
-
那么当您选择一个选项时,工具提示类将被更改?
-
你能做同样的jsfiddle吗
-
Jim Fahad,是的,工具提示类和工具提示数据放置会改变。
-
Ankur140290 - 我在帖子中添加了一个小提琴。
-
您可以了解更多关于 -Tooltip 插件是当用户将鼠标指针移到元素上时出现的小弹出框:w3schools.com/bootstrap/bootstrap_tooltip.asp
标签: javascript jquery html twitter-bootstrap