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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 07:48:38  来源:igfitidea点击:

Uncaught SyntaxError: Unexpected string

javascriptjqueryjavascript-events

提问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.keyCodeand changing tmpin the ifstatement to event.keyCodebut I cannot identify the problem.

我已经尝试tmp = event.keyCodetmpif声明中更改为,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" )