This is giving me "4: Uncaught SyntaxError: Unexpected token ILLEGAL":
(function() {
var select = document.getElementById('select-card');
select.onchange = function() { };
})();
What should I be doing differently?
This is giving me "4: Uncaught SyntaxError: Unexpected token ILLEGAL":
(function() {
var select = document.getElementById('select-card');
select.onchange = function() { };
})();
What should I be doing differently?
Share Improve this question asked Feb 19, 2015 at 17:28 RichardRichard 65.7k135 gold badges356 silver badges571 bronze badges 2- Maybe the select keyword is bugging. It's on the window object. – Mouser Commented Feb 19, 2015 at 17:30
-
2
Actually that's not it, you have a non-printing character in front of
select
. See a red dot at jsFiddle. – Teemu Commented Feb 19, 2015 at 17:36
3 Answers
Reset to default 6I expect that you have an element with id select-card
. Your code is otherwise fine.
But you should be using.
select.addEventListener("change", function(){ } );
Edit the code to this: select.onchange = (function() { });
Whenever you're doing a function expression and calling it immediately, you need those parens because there's a parsing ambiguity otherwise.
I couldn't wrap my head around this. The code is correct however is was bugging still. Found it, it appeared when I converted my test page from UTF8 to ANSI:
There is a incorrect return/character in your code. That is causing the bug.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744387024a4571715.html
评论列表(0条)