This article describes the solution to the JS prompt: Uncaught SyntaxError:Unexpected token ) error. Share it for your reference, as follows:
Uncaught SyntaxError: Unexpected token )
The following code throws this exception:
<div class="Hd_live_Sharediv left"> <a href="javascript:void()" onclick="loadLivePlayer('ud')" style="width:40px;">Ultra clear</a> <a href="javascript:void()" onclick="loadLivePlayer('hd')" style="width:40px;">HD</a> <a href="javascript:void()" onclick="loadLivePlayer('sd')" style="width:40px;">Smooth</a> </div>
What may cause this error:
1. The href attribute value is "JavaScript:void()", and no "0" is added in the brackets.
The usage format of the void operator is as follows:
①. javascript:void (expression)
②. javascript:void expression
expression is a Javascript standard expression to be calculated. The brackets on the outside of the expression are selected, but writing them is a good habit. (Implementation version Navigator 3.0 )
You specify the hyperlink by using the void operator. The expression will be calculated but nothing is loaded in the current document.
<div class="Hd_live_Sharediv left"> <a href="javascript:void(0)" onclick="loadLivePlayer('ud')" style="width:40px;">Ultra clear</a> <a href="javascript:void(0)" onclick="loadLivePlayer('hd')" style="width:40px;">HD</a> <a href="javascript:void(0)" onclick="loadLivePlayer('sd')" style="width:40px;">Smooth</a> </div>
2. The onclick event handling function "loadLivePlayer" does not add the return value, resulting in javascript:void(0) being executed. You should add: return false;
For more information about JavaScript, readers who are interested in reading this site's special topic:Summary of JavaScript value transfer operation skills》、《Summary of JavaScript encoding operation skills》、《Summary of json operation skills in JavaScript》、《Summary of JavaScript switching effects and techniques》、《Summary of JavaScript search algorithm skills》、《Summary of JavaScript animation special effects and techniques》、《Summary of JavaScript Errors and Debugging Skills》、《Summary of JavaScript data structure and algorithm techniques》、《JavaScript traversal algorithm and skills summary"and"Summary of JavaScript mathematical operations usage》
I hope this article will be helpful to everyone's JavaScript programming.