I am new to vscode and and hardly get bothered by one thing.
var template = "<div> <input type="text" class="input"> <input type="text" class="input"> <input type="text" class="input"> <input type="text" class="input"> <input type="text" class="input"> </div> "
I have no clue why vscode is not wrapping all those line in quote. It just throws a syntax error. It reads when they aligned in one line but when I break the line to make it look good, the code is not working. Any idea?
You can do like this:
var template = ` <div> <input type="text" class="input"> <input type="text" class="input"> <input type="text" class="input"> <input type="text" class="input"> <input type="text" class="input"> </div> `; document.body.innerHTML = template;
If you aren't familiar with template strings here is the MDN documentation .
You can try this way. Just use single quotes to surround the variable string, and use backslashes to change lines.
var template = '<div>\ <input type="text" class="input"> \ <input type="text" class="input"> \ <input type="text" class="input"> \ <input type="text" class="input"> \ <input type="text" class="input"> \ </div>'; document.body.innerHTML = template;
It fails because of multiple reasons:
The only way you can fix it is like in the example below. You have to open and close the variable and use a +
to continue the variable in the next line:
var template = '<div>' + '<input type="text" class="input">' + '<input type="text" class="input">' + '<input type="text" class="input">' + '<input type="text" class="input">' + '<input type="text" class="input">' + '</div>'; document.body.innerHTML = template;
or you can
var template = '<div>\
<input type="text" class="input">\
<input type="text" class="input">\
<input type="text" class="input">\
<input type="text" class="input">\
<input type="text" class="input">\
</div>'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.