Javascript 将空字符串返回到ES6模板字符串中
我正在做以下工作:Javascript 将空字符串返回到ES6模板字符串中,javascript,ecmascript-6,template-strings,Javascript,Ecmascript 6,Template Strings,我正在做以下工作: return this.innerHTML = ` <input value = ${this.value ? this.value : ''} placeholder=${this.placeholder} ></input> ` return this.innerHTML = ` <input value = "${this.value ? this.value : ''}"
return this.innerHTML = `
<input
value = ${this.value ? this.value : ''}
placeholder=${this.placeholder}
></input>
`
return this.innerHTML = `
<input
value = "${this.value ? this.value : ''}"
placeholder="${this.placeholder}"
></input>
`
返回this.innerHTML=`
`
现在的问题是,如果this.value
未定义,未定义为字符串设置为输入值,这就是为什么我尝试将空字符串返回到inputs-value属性。这不起作用,然后我将placeholder=${This.placeholder}
作为字符串放入value属性中
我在谷歌上搜索了一会儿,没有找到任何答案,这可能吗
非常感谢您的帮助。您没有将值和占位符用双引号括起来
返回this.innerHTML=`
`
您没有将值和占位符用双引号括起来
返回this.innerHTML=`
`