最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sample HTML to test javascript codes - Stack Overflow

programmeradmin1浏览0评论

I have just started learning Javascript and Ok here is a code I want to try and see it in the browser, so I create a test.js file and put this in it:

function useless(callback) {
    return callback
}

var text = 'Amigo';

assert(
    useless(function(){ return text; }) === text,
    "The useless function works! " + text);

But still there is more, I should write a minimum HTML page than can call this function, What is sample HTML to host this method in it?

I have written something like this but still there is something wrong with it:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>

<script src="hehe.js" >
    useless('Amigo');
    window.onload=useless('Amigo')
</script>

</body>
</html>

I have just started learning Javascript and Ok here is a code I want to try and see it in the browser, so I create a test.js file and put this in it:

function useless(callback) {
    return callback
}

var text = 'Amigo';

assert(
    useless(function(){ return text; }) === text,
    "The useless function works! " + text);

But still there is more, I should write a minimum HTML page than can call this function, What is sample HTML to host this method in it?

I have written something like this but still there is something wrong with it:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>

<script src="hehe.js" >
    useless('Amigo');
    window.onload=useless('Amigo')
</script>

</body>
</html>
Share Improve this question asked Apr 3, 2013 at 20:19 user1899082user1899082 4
  • 1 So the book you're reading doesn't teach you how to incorporate js to a page and call functions? – zerkms Commented Apr 3, 2013 at 20:20
  • @zerkms : No it doesn't have the HTML part...realign form Javascript Ninja book – user1899082 Commented Apr 3, 2013 at 20:21
  • "I have written something like this" --- where did you see that syntax? Just put something random and expected it to work? – zerkms Commented Apr 3, 2013 at 20:21
  • 1 Take a look at jsfiddle and jsbin – Pointy Commented Apr 3, 2013 at 20:21
Add a ment  | 

1 Answer 1

Reset to default 2
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<script type="text/javascript" src="hehe.js"></script>
<script  >
    useless('Amigo');
    window.onload=useless('Amigo')
</script>

</body>
</html>

You can load the source in a separate script from the inline one that you call it in. Note that this assumes that hehe.js is in the root directory of your site.

For testing js in general jsFiddle is a nice resource that lets you define your html/js/css and experiment with small changes without having to write out all the files.

发布评论

评论列表(0)

  1. 暂无评论