How to display underline in javascript string? - Stack Overflow

I have the following javascript code:var result = ("Please enter your name","Andrew"

I have the following javascript code:

var result = ("Please enter your name","Andrew");

and i wanted to underline the word "name" in the above message.

This is trivial but i have no clue after searching for escape code representation for underline. Or is the above possible in javascript ?

I have the following javascript code:

var result = ("Please enter your name","Andrew");

and i wanted to underline the word "name" in the above message.

This is trivial but i have no clue after searching for escape code representation for underline. Or is the above possible in javascript ?

Share Improve this question edited Jul 29, 2011 at 2:12 Marty 39.5k19 gold badges97 silver badges163 bronze badges asked Jul 29, 2011 at 2:10 Andrew NgAndrew Ng 891 gold badge2 silver badges8 bronze badges 4
  • 3 The code doesn't make sense. It's equivalent to var result = "Andrew";, the first string is just discarded. Besides, any formatting like underlining depends on how you display the message, so you have to specify that also. – Guffa Commented Jul 29, 2011 at 2:15
  • A demo of Guffa's ment: jsfiddle/Fw9RX – Jared Farrish Commented Jul 29, 2011 at 2:17
  • Maybe this is just a simplified example, but why do you want to underline "name"? Do you find a lot of users misread the question and enter their favourite colour? – nnnnnn Commented Jul 29, 2011 at 2:24
  • he probably mean to put square bracket [ .. ] instead of the (...) – Soren Commented Jul 29, 2011 at 2:28
Add a ment  | 

3 Answers 3

Reset to default 2

If the example code given had a typo and should've read like this:

var result = window.prompt("Please enter your name","Andrew");

then the answer is that you can't format the text or change the labels on the buttons or anything. This applies to the built-in alert() and confirm() as well as to prompt().

It's a bit more work, but you can implement your own equivalent dialog by building one from HTML using a transparent <div> to cover the rest of your page so that users can't interact with the rest of the page until the dialog closes. (Or use a translucent <div> to make it more obvious to the user that the rest of the page is "disabled".)

I would not bother coding this from scratch when there are lots of JS libraries that do it for you. The jQuery dialog is pretty easy to use, to name just one option.

If this is ending up on a web page you should just be able to use:

var result = ("Please enter your <u>name</u>","Andrew");

...but I'm not exactly sure what it is you're intending to do. Can you add more detail to your question?

var result = ("Please enter your <u>name</u>","Andrew");

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744256106a4565407.html

相关推荐

  • How to display underline in javascript string? - Stack Overflow

    I have the following javascript code:var result = ("Please enter your name","Andrew"

    8天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信