Sop*_*oph 1 javascript jquery dom
我有以下代码
var aVar = "sample text";
alert(aVar);
$(this).replaceWith( "<input type='text' value=" + aVar + " id='laID' style='width: 100px; padding-right:20px; color:white;'/>");
Run Code Online (Sandbox Code Playgroud)
警报消息框返回预期值:"示例文本".但是,DOM元素使用以下值生成:"sample".现在,如果我按照以下方式尝试它:
$(this).replaceWith( "<input type='text' value='sample text' id='laID' style='width: 100px; padding-right:20px; color:white;'/>");
Run Code Online (Sandbox Code Playgroud)
不幸的是,我别无选择,只能从变量中读取值,我不能硬编码.希望有人能指导我这个!thankss
更改:
value=" + aVar + " id='
Run Code Online (Sandbox Code Playgroud)
至:
value='" + aVar + "' id='
Run Code Online (Sandbox Code Playgroud)
应引用属性.
你错过了引号.用这个:
$(this).replaceWith( "<input type='text' value='" + aVar + "' id='laID' style='width: 100px; padding-right:20px; color:white;'/>");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
206 次 |
| 最近记录: |