Javascript 未捕获的语法错误:意外的字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11954623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught SyntaxError: Unexpected string
提问by William Isted
I'm having difficulty getting the following to work, all I get from Chrome's Console is Uncaught SyntaxError: Unexpected string
.
我很难让以下内容工作,我从 Chrome 的控制台得到的只是Uncaught SyntaxError: Unexpected string
.
I have tried tmp = event.keyCode
and changing tmp
in the if
statement to event.keyCode
but I cannot identify the problem.
我已经尝试tmp = event.keyCode
并tmp
在if
声明中更改为,event.keyCode
但我无法确定问题所在。
function showSearching() {
alert ("Hello World");
}
$('#search').bind('keydown', function() {
tmp = Number(event.keyCode);
if ( ( tmp=<"48" && tmp=>"90" ) || ( tmp=<"96" && tmp=>"111" ) || ( tmp=<"186" && tmp=>"222" ) ) {
showSearching();
}
});
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<input id="search" type="text">
回答by Adil
Wrong syntax of relational operator in if statement.
if 语句中关系运算符的语法错误。
change => to >=
and =< to <=
改变=> to >=
和=< to <=
$('#search').bind('keydown', function() {
tmp = Number(event.keyCode);
if ((tmp <= "48" && tmp >= "90") || (tmp <= "96" && tmp >= "111") || (tmp <= "186" && tmp >= "222")) {
showSearching();
}
});?
回答by codingbiz
Change =<
to <=
更改=<
为<=
if ( ( tmp<="48" && tmp>="90" )