在用javascript编写html时出现引用问题

在用javascript编写html时出现引用问题,javascript,jquery,html,quotations,Javascript,Jquery,Html,Quotations,我正在用javascript编写一个html结构,单击链接时需要返回它 return '<div class="contactForm">'+ '<input type="text" name="contactName" onBlur="if (this.value == "") {this.value == "Name";}" onFocus="if ((this.value == "") || (this.value == "Name")) {this.value =

我正在用javascript编写一个html结构,单击链接时需要返回它

  return '<div class="contactForm">'+
'<input type="text" name="contactName" onBlur="if (this.value == "") {this.value == "Name";}" onFocus="if ((this.value == "") || (this.value == "Name")) {this.value = "";};" value="Name" style="">'+

如何编写返回部分,以便在HTML页面中正确地获取它?我相信这是由于引号放错了位置。我在页面中看到此错误源在需要属性名时看到了引号

您需要使用\\\\对字符串内的引号进行双转义:一次用于字符串本身,一次用于内联JavaScript

return '<div class="contactForm">'+
    '<input type="text" name="contactName" onBlur="if (this.value == \\\"\\\") {this.value == \\\"Name\\\";}" onFocus="if ((this.value == \\\"\\\") || (this.value == \\\"Name\\\")) {this.value = \\\"\\\";};" value="Name" style="">'+
返回“”+
''+
如果你想让它更清晰一点,你可以使用单引号,只需要转义一次

return '<div class="contactForm">'+
    '<input type="text" name="contactName" onBlur="if (this.value == \'\') {this.value == \'Name\';}" onFocus="if ((this.value == \'\') || (this.value == \'Name\')) {this.value = \'\';};" value="Name" style="">'+
返回“”+
''+

您需要使用\\\\对字符串内的引号进行双转义:一次用于字符串本身,一次用于内联JavaScript

return '<div class="contactForm">'+
    '<input type="text" name="contactName" onBlur="if (this.value == \\\"\\\") {this.value == \\\"Name\\\";}" onFocus="if ((this.value == \\\"\\\") || (this.value == \\\"Name\\\")) {this.value = \\\"\\\";};" value="Name" style="">'+
返回“”+
''+
如果你想让它更清晰一点,你可以使用单引号,只需要转义一次

return '<div class="contactForm">'+
    '<input type="text" name="contactName" onBlur="if (this.value == \'\') {this.value == \'Name\';}" onFocus="if ((this.value == \'\') || (this.value == \'Name\')) {this.value = \'\';};" value="Name" style="">'+
返回“”+
''+
var元素=“”;
元素+='';
元素+='';
返回元素;
var元素=“”;
元素+='';
元素+='';
返回元素;