内联 jquery 字符串 - 为某些单词添加粗体字体
inline jquery string - add bold font to certain words
我有一个jquery的内联字符串,它显示动态文本字符串,如下所示:
$( "#submit_buttonA" ).attr('update-confirm', '{% trans "Are you sure you want to change the language of the website from" %} ' + $('#id_language_code option[value=' + '{{ user.get_profile.language_preference }}' + ']').text() + ' {% trans "to" %} ' + $('#id_language_code option[value=' + newLanguageCode + ']').text() + '{% trans "?" %}');
这给了我以下内容:
您确定要将网站的语言从葡萄牙语(巴西)更改为意大利语 - 意大利语吗?
我现在正在尝试以粗体字体制作语言名称,但我采用的每种方法都会将 字符呈现到屏幕上。
这就是我想要实现的目标:
您确定要将网站的语言从葡萄牙语(巴西)更改为意大利语 - 意大利语吗?
所以我尝试了以下方法:
$( "#submit_buttonA" ).attr('update-confirm', '{% trans "Are you sure you want to change the language of the website from" %}<b> ' + $('#id_language_code option[value=' + '{{ user.get_profile.language_preference }}' + ']').text() + '</b> {% trans "to" %}<b> ' + $('#id_language_code option[value=' + newLanguageCode + ']').text() + '</b>{% trans "?" %}');
这就是我得到的:
是否确实要将网站语言从 português (Brasil) 更改为 Italiano - Italiano?
编辑:根据请求添加代码
$('a[update-confirm]').click(function(ev) {
var href = $(this).attr('href');
if (!$('#updateConfirmModal').length) {
//please wait included in the line of code below.
$('body').append('<div id="updateConfirmModal" class="modal modal-confirm-max-width" role="dialog" aria-labelledby="updateConfirmLabel" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true"><icon class="icon-remove"></icon></button><h4 class="modal-title" id="updateConfirmLabel">{% trans "Confirm Language Change" %}</h4></div><div class="modal-body"></div><div class="modal-footer"><button class="btn" data-dismiss="modal" aria-hidden="true">{% trans "Cancel" %}</button> <span class="visible-phone"><br /></span><a class="btn-u btn-u-blue" id="updateConfirmOK" onclick="submitForm();showProgressAnimation();">{% trans "Update Language View" %} - {% trans "Language Change" %}</a></div></div>');
}
$('#updateConfirmModal').find('.modal-body').text($(this).attr('update-confirm'));
$('#updateConfirmOK').attr('href', href);
$('#updateConfirmModal').modal({show:true});
return false;
});
更改此行:
$('#updateConfirmModal').find('.modal-body').text($(this).attr('update-confirm'));
到这一行:
$('#updateConfirmModal').find('.modal-body').html($(this).attr('update-confirm'));
请参考原帖中的评论,关注整个过程
只需将 .text() 更改为 .html()。
.text() 从字面上呈现所有内容,而 .html() 渲染普通 HTML。
相关文章:
- 使用jQuery检查提交时添加到句子中的单词
- 如何使用Javascript在给定的句子中找到大写单词并在其前面添加一个字符
- 通过PHP将单词添加到游戏中
- RegEx:在单词边界添加加号
- 将组成单词的字符添加到数组的开头
- 使用javascript为单词添加样式
- 使用JavaScript添加单词样式,但避免链接
- 单词中的元素每个都添加类
- 跳过用户输入的文本字符串中的特殊字符,并在 Javascript 中的每个单词后添加连字符
- 添加一个“;以及“;到String-js/Angular中的最后一个单词
- 添加“<strong>"到某个单词使用handlers.js
- 考虑到我在JavaScript中使用.replace.更改了特定单词中间的另一个字符,我如何在该单词之前添加字符
- 找到包含单词的特定链接并添加到数组中
- struts2 文本区域 仅为一个单词添加样式
- 在 JavaScript 中使用正则表达式在单词的任一侧添加空格
- 忽略模糊匹配并使用 JavaScript 添加精确的单词模式匹配
- 使用 jQuery 为某些单词添加下划线
- 将单击的单词添加到字符串中
- 在字符串的任何位置添加单词
- Javascript的PHP函数:扫描字符串并在数组中添加单词