在JavaScript中构建字符串时,对字符串的某些区域进行粗分析

时间:2015-03-02 15:29:02

标签: javascript string

我正在使用JavaScript构建一个存储在文本区域的字符串,我想在字符串中加粗某些值/文本。我已经尝试了.bold()<b> / <strong>标记,但它们不会使文字变为粗体。相反,它们会显示标记。

这是我的代码:

        var msg = username.val() + " is requesting that the Custody of the credentialing record for " + last.val() + ", " + first.val() + " (" + identifierTxt.val() + ") be transferred to " + uicTxt.val() + ", " + mtfName.val() + " NLT " + custodyDate.val() + ". \n\n";
        if (reasonId.val() == "") {
            msg = msg +  "Reason: <b>Reason Not Entered></b>"
        }
        else {
            if (reasonId.val() == 99999) {
                msg = msg + "Reason: " + $("#ReasonId option:selected").text() + " - " + otherReason.val() + "\n\n";
            }
            else {
                msg = msg + "Reason: " + $("#ReasonId option:selected").text() + "\n\n";
            }
        }

        msg = msg + "My contact information is as follows: \nUsername: " + username.val() + "\n";
        if (email.val() == "") {
            msg = msg + "Email: <b><Email Not Entered></b> \n";
        }
        else {
            msg = msg + "Email: " + email.val() + "\n";
        }

        if (phone.val() == "") {
            msg = msg + "Phone: <Phone Not Entered> \n";
        }
        else {
            msg = msg + "Phone: " + phone.val() + " (" + phoneType.val() + ")\n\n";
        }
 msg = msg + "Credentials Coordinator: \nName: " + publicAffarsTxt.val() + " \nCommercial Phone: " + mtfPhone.val() + "\nDSN Phone: " + mtfDSN.val() + "\nFax Phone: " + mtfFax.val() + "\nEmail Address: " + mtfEmal.val();

        $("#MessageTxt").val(msg);
    }

我也在使用剃须刀,我的文字区域是:      @ Html.TextAreaFor(model =&gt; model.MessageTxt,new {@class =“form-control”,@ readonly =“readonly”,@ code = 50,@rows = 15})

0 个答案:

没有答案