这个连接的JavaScript代码不起作用.我在关闭脚本标签之前尝试了一个警告,它显示但下面的代码我想在第三个或不同的文本字段中显示结果.
HTML:
<input type="text" id="field"><br>
<input type="text" id="str2"><br>
<input type="text" id="str3"><br>
<button onclick="concate()">Concatenate</button>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
var s=document.getElementById("field").value;
var t=document.getElementById("str2").value;
var st=document.getElementById("str3").value;
function concate()
{
st=s+t;
document.getElementById("str3").value.innerHTML=st;
console.log(st);
document.write(st);
}
Run Code Online (Sandbox Code Playgroud)
.value.innerHTML应该没有功能:
document.getElementById("str3").value = st;
Run Code Online (Sandbox Code Playgroud)
您还应该在函数内部获取字段值并使用关闭函数定义},请查看下面的示例.
希望这可以帮助.
function concate()
{
var s=document.getElementById("field").value;
var t=document.getElementById("str2").value;
document.getElementById("str3").value=s+t;
}Run Code Online (Sandbox Code Playgroud)
<input type="text" id="field"><br>
<input type="text" id="str2"><br>
<input type="text" id="str3"><br>
<button onclick="concate()">Concatenate</button>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1008 次 |
| 最近记录: |