Ever need to print quotation marks in a JavaScript string. That is not too bad, right? All you have to do is use the other set of quotation marks. If you need to use double quotation marks in a string, then you define the string by using single quotations, that is not hard. Now, what if you needed to use both sets of quotation marks in a string? That is a little bit harder. In this case you could split the string into many different parts and then just append the pieces together, but that can get to be too much work, not to mention confusing. It would be easier to take a look at the table bellow and use JavaScript's escape characters.
| Character | Meaning |
| \b | Backspace |
| \f | Form feed |
| \n | New line |
| \r | Carriage return |
| \t | Tab |
| \' | Single quote or apostrophe (') |
| \" | Double quote (") |
| \\ | Backslash (\) |
| \XXX | XXX is an octal number (between 0 and 377) that represent the Latin-1 character equivalent. For example \251 is the octal code for the copyright symbol. |
| \xXX | XX is a hexadecimal number (between 00 and FF) that represent the Latin-1 character equivalent. For example \xA9 is the hexadecimal code for the copyright symbol. |
| \uXXXX | XXXX is a hexadecimal number (between 00 and FF) that represent the Unicode character equivalent. For example \u00A9 is the hexadecimal code for the copyright symbol. (Note: Unicode is only supported by JavaScript 1.3) |
The string "\tTom said \"Hello to everyone!\"\nSo did Mary." would print:
- Tom said "Hello to everyone!"
So did Mary.
1)
2)
alert('OK Then!\r\rYou want a neat box like \"this\" one?\r\rWell!\r\rYou\'ll need:\rBrains\tBeauty\t\tTalent\rMoney\tDog food\t\tLuck\rA Cat\tEye of Newt\tA Shrubbery!\r\rAnd the ability to \'read\' this tutorial.\r\rOK?')
3)Notice that because the backslash itself is used as the escape character, you cannot directly type one in your script! If you want to use a backslash, you must type two of them together (\\).
document.write('The path to the file is C:\\program files\\mystuff\\readme.txt.');
document.write('He thought for one moment and then said, "I really didn/'t suspect the problem to be with the hard drive."');
Forgetting to use escape characters properly will result in errors in your JavaScripts. Take care that you get them right!
| VHF Radio |
1 comments:
hey! i'm going to cali this weekend and won't be back until september...here is the website i was talking about where i made extra summer cash. Later! the website is here
Post a Comment