sample HTML to test javascript codes - Stack Overflow

I have just started learning Javascript and Ok here is a code I want to try and see it in the browser,

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745281219a4620289.html

相关推荐

  • sample HTML to test javascript codes - Stack Overflow

    I have just started learning Javascript and Ok here is a code I want to try and see it in the browser,

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信