SyntaxError: identifier starts immediately after numeric literal
Today I wrote a onclick() method, there is such a variable 4028b88161c881ff0161c88b80dc0002
I need to pass the value of this variable into the method, but it never works:
I found that directly var aa =4028b88161c881ff0161c88b80dc0002 ;js is holding the error
The solution is as follows:
$(function(){
var str = “509edbe9-2914-431f-9128-97d368b7da0b”;
//The wrong way to write it
var html = ‘<button class=”button” id=”ensure” onclick=”test(str)”>OK</button>’;// Passing a string as an argument to a function reports an error directly
//The correct way to write it
var html = ‘<button class=”button” id=”ensure” onclick=”test(\”+str+’\’)”>OK</button>’;//execute correctly, note that the first \ is followed by two single quotes
$(“#dd”).append(html);
});
function test(id){
console.log(id);
}
<div id=”dd”></div>
Similar Posts:
- How to Solve Error: Cannot set property ‘onclick’ of null
- How to deal with the error “cannot read property ‘set state’ of undefined” in react
- Using CEF as user interface
- [How to Solve] Cannot set property ‘onclick’ of null
- Interaction between web browser and JavaScript in WPF
- [Solved] IllegalArgumentException: object is not an instance of declaring class
- Gradle Could not find method leftShift() for arguments
- [Solved] Java Call Error: java.lang.IllegalArgumentException: wrong number of arguments
- Common error reports and solutions of ionic 3
- window.location And window.open The difference between