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> <a href="javascript:void()" onclick="loadLivePlayer('ud')">Ultra-clear</a> <a href="javascript:void()" onclick="loadLivePlayer('hd')">High Definition</a> <a href="javascript:void()" onclick="loadLivePlayer('sd')">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. (Implement 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> <a href="javascript:void(0)" onclick="loadLivePlayer('ud')">Ultra-clear</a> <a href="javascript:void(0)" onclick="loadLivePlayer('hd')">High Definition</a> <a href="javascript:void(0)" onclick="loadLivePlayer('sd')">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 related content, please check out the topics of this site: "Summary of JavaScript value transmission 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 effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm skills", "Summary of JavaScript traversal algorithms and techniques" and "Summary of JavaScript mathematical operations usage"
I hope this article will be helpful to everyone's JavaScript programming.