I'm learning JavaScript and jQuery. I'm trying to build a simple web page with buttons that navigate to another page upon click via a switch-case statement.
I've added a local jQuery script to my .html file, but nothing seems to happen when I click the buttons.
Demo can be found here: /
The html code is:
<head>
<script src="//ajax.googleapis/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
$("input[type='button']").click(function() {
switch(this.id) {
case 'x':
window.location.href = "";
break;
case 'y':
window.location.href = "";
break;
case 'z':
window.location.href = "";
break;
}
});
</head>
<body>
<input type="button" value="google" style="width:120px" id="x"><br>
<input type="button" value="yahoo" style="width:120px" id="y"><br>
<input type="button" value="stackoverflow" style="width:120px" id="z"><br>
</body>
I'm learning JavaScript and jQuery. I'm trying to build a simple web page with buttons that navigate to another page upon click via a switch-case statement.
I've added a local jQuery script to my .html file, but nothing seems to happen when I click the buttons.
Demo can be found here: http://jsfiddle/VmYLy/
The html code is:
<head>
<script src="//ajax.googleapis./ajax/libs/jquery/1.11.0/jquery.min.js"></script>
$("input[type='button']").click(function() {
switch(this.id) {
case 'x':
window.location.href = "http://google.";
break;
case 'y':
window.location.href = "http://yahoo.";
break;
case 'z':
window.location.href = "http://stackoverflow.";
break;
}
});
</head>
<body>
<input type="button" value="google" style="width:120px" id="x"><br>
<input type="button" value="yahoo" style="width:120px" id="y"><br>
<input type="button" value="stackoverflow" style="width:120px" id="z"><br>
</body>
Share
Improve this question
edited Dec 28, 2015 at 15:05
Nat Naydenova
7992 gold badges12 silver badges30 bronze badges
asked Mar 22, 2014 at 12:15
AlexAlex
2,0724 gold badges42 silver badges76 bronze badges
5
- 1 have you actually tried this in your machine or just in jsfiddle? I'm afraid you can't redirect in jsfiddle – G.Mendes Commented Mar 22, 2014 at 12:18
-
it seems to be working fine, fiddle trows error
Refused to display 'http://stackoverflow./' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
– T J Commented Mar 22, 2014 at 12:19 - of course i've tried this on my machine. nothing happens :/ how can i be sure the jquery library is loaded correctly to the browser? – Alex Commented Mar 22, 2014 at 12:20
- it doesn't work in jsfiddle but when you look in your console you find this: Load denied by X-Frame-Options: google.de/?gfe_rd=cr&ei=8X8tU5uSGMmK8Qeg7YCgDg does not permit cross-origin framing. – Evolutio Commented Mar 22, 2014 at 12:20
-
What's wrong with using plain old
<a href=...>
? – greut Commented Mar 22, 2014 at 12:20
1 Answer
Reset to default 4It works fine in fiddle. only prob i can think of is to wrap your code in ready()
. This might not be causing problem in fiddle since you've selected onLoad
option.
$(document).ready(function(){
$("input[type='button']").click(function() {
switch(this.id) {
case 'x':window.location.href = "http://google."; break;
case 'y': window.location.href="http://yahoo."; break;
case 'z': window.location.href = "http://stackoverflow."; break;
}
});
})
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744802933a4594602.html
评论列表(0条)