javascript - 内联 jquery 字符串 - 为某些单词添加粗体

标签 javascript jquery html css

我有一个内联的 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 "?" %}');

这给了我以下信息:

您确定要将网站语言从 português(巴西)更改为 Italiano - italiano 吗?

我现在正尝试将语言名称设为粗体,但我采用的每种方法都会将 < b> 字符呈现到屏幕上。

这就是我要实现的目标:

您确定要将网站语言从português (Brasil) 更改为Italiano - italiano吗?

所以我尝试了以下方法:

$( "#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(巴西)更改为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>&nbsp;&nbsp;<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'));

完整流程请引用原帖评论

关于javascript - 内联 jquery 字符串 - 为某些单词添加粗体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27180199/

相关文章:

jquery - JqG​​rid 单元格中的选择框

javascript - jquery从字符串重建选择器

jquery - swiper自定义分页只滑动一次

html - HTML 中 TextArea 内的按钮

html - 为什么跨度中的所有边距都不起作用?他们只接受一个 margin 还是什么?

javascript - jQuery 插件,获取原始元素的 .data()

javascript - 延迟交换嵌套循环中的数组元素

html - 如何在同一行上对齐两个输入框但两端

Javascript 方法

javascript - 并排对齐 div,没有空白的黑色空间