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
1 Answer
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
评论列表(0条)