javascript - I can't import a .js file on a .html document -


i have little trouble: on server published .js file declared function simplifies document.write() function:

function print(id, text){document.getelementbyid(id).innerhtml = text;} 

i tested code calling function print("paragraph", "hello, world!"); , works, don't know why when created new .html file , imported easyjs_demo.js file , in <script> tag called print function, didn't work:

<body>       <p id="paragraph"></p>       <script src="easyjs_demo.js">       print("paragraph", "hello, world!");       </script> </body> 

do know how can import .js file wothout having bugs this? thank much!

you can't combine includes , code, try separating external file, , inline code this:

<script src="easyjs_demo.js"></script> <script>   print("paragraph", "hello, world!"); </script> 

demo plunker here.


multiple sources show if specify src attribute, user agent ignores inline code:


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -