JavaScript Tutorial/String/String Declaration

Материал из Web эксперт
Перейти к: навигация, поиск

Define HTML tags as the string variable

<HTML>
<BODY>
<SCRIPT language="JavaScript">
<!--
    var myheading="This is My Web Page!";
    var linktag="<A HREF="http://www.wbex.ru">Web Site Link!</A>";
    var sometext="This text can be affected by other statements.";
    var begineffect="<U>";
    var endeffect="</U>";
    var newsection="<BR>";
    document.write(myheading);
    document.write(newsection);
    document.write(begineffect);
    document.write(sometext);
    document.write(endeffect);
    document.write(newsection);
    document.write(linktag);
    document.write(newsection);
    document.write(sometext);
//-->
</SCRIPT>
</BODY>
</HTML>


Output string value and length

<html>
<head>
<script type="text/javascript" language="javascript">
<!-- //
onload = function(){
 var myString = "AAA";
 document.write(myString + " has a length of " + myString.length + " characters.");
 }
// -->
</script>
</head>
<body>
</body>
</html>