Thứ Tư, 21 tháng 8, 2013

JavaScript code inside the script element

Example 1:
<script type=”text/javascript”>
    function sayHi(){
                 alert(“Hi!”);
    }
</script>
Example 2: the following code causes an error when loaded into a browser because </script> not string 
<script type=”text/javascript”>
     function sayScript(){
          alert(“</script>”);
    }
</script>
This problem can be avoided easily by escaping the “/” character, as in this example:
<script type=”text/javascript”>
             function sayScript(){
            alert(“<\/script>”);
             }
</script>
Example 3:The value of srcis a URL linked
<script type=”text/javascript” src=”example.js”></script>

or if javascrip in  XHTML

<script type=”text/javascript” src=”example.js”/>
or
<script type=”text/javascript” src=”http://www.somewhere.com/afile.js”></script>

Không có nhận xét nào:

Đăng nhận xét