我想将搜索栏中的值显示到“”的搜索结果中。
这就是我到目前为止所得到的,为什么它不起作用?
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<input type="text" id="autocomplete" value="" placeholder="Search for names.." title="Type in a name">
<p>
Search results for "<span id="result"></span>"
</p>
<button onclick="myname();"> Button </button>
<script>
function myname () {
document.getElementById("autocomplete").value = document.getElementById("result").innerHTML;
}
</script>
</body>
</html>
最佳答案
您想要复制的数据位于等号的右侧,您想要放置数据的位置位于等号的左侧。
document.getElementById("result").innerHTML = document.getElementById("autocomplete").value;
关于javascript - 在 HTML 中显示值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50379290/