简体   繁体   中英

Partial bold text in asp.net

This is how I am adding asp.net label,

<asp:Label ID="lblFruitNameAndDate" runat="server" ClientIDMode="Static"></asp:Label>

In JavaScript I am trying this,

  $("#lblFruitNameAndDate").text(webServiceData.FruitName + " '<b> On: " + webServiceData.FruitCrateDate + "</b>");

but on screen i am getting <b> tags.

the .text() method doesn't accept arguments, its used for getting the text value not setting it, here are the jquery docs on .text()

You'd need to use .html() which does set dom content/elements

    $("#lblFruitNameAndDate").html(
        webServiceData.FruitName + " '<b> On: " + webServiceData.FruitCrateDate + "</b>"
    );

A demonstration of bold method can be found at W3Schools like this:

document.write("<p>Bold: " + txt.bold() + "</p>");

and you should also consider that bold() method is not standard, and may not work as expected in all browsers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM