gpt4 book ai didi

javascript - 我将如何附加结果值?

转载 作者:行者123 更新时间:2023-11-29 19:03:04 25 4
gpt4 key购买 nike

function getNote() {
var textField = document.getElementById('textField').value;
var result = document.getElementById('result');
result.innerHTML = textField;
}
var submitButton = document.getElementById('submitButton');
submitButton.addEventListener('click',getNote);
<html lang="en">
<head>
<div id="wrapper">
<div class="topnav" id="myTopnav">
<a href="#home">NoteTaker</a>

</div>
<title>Note Taker</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"></head>
<body id="style">
<div id ="centerField">
<h1> New Note</h1>
<textarea id="textField"rows="8" cols="70%" placeholder ="Type Here."></textarea>
<br>
<button type="button" id="submitButton" class="btn btn-warning">Submit Information</button>
</div>
<div id ="leftField" >
<h2> Saved Notes</h2>
<p id='result'></p></div>
<div id="container"></div>

</div>
</div>
</body>
</html>

我希望每个值都不断添加到字段中。因此,当我提交测试然后提交帮助时,该字段应该同时包含两者。现在它添加然后替换,现在我很难过。

最佳答案

如果您不想覆盖它并继续附加,请获取旧值并向其添加新值。

result.innerHTML = result.innerHTML + " " + textField; 

function getNote() {
var textField = document.getElementById('textField').value;
var result = document.getElementById('result');
result.innerHTML = result.innerHTML + " " + textField;
}
var submitButton = document.getElementById('submitButton');
submitButton.addEventListener('click',getNote);
<html lang="en">
<head>
<div id="wrapper">
<div class="topnav" id="myTopnav">
<a href="#home">NoteTaker</a>

</div>
<title>Note Taker</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"></head>
<body id="style">
<div id ="centerField">
<h1> New Note</h1>
<textarea id="textField"rows="8" cols="70%" placeholder ="Type Here."></textarea>
<br>
<button type="button" id="submitButton" class="btn btn-warning">Submit Information</button>
</div>
<div id ="leftField" >
<h2> Saved Notes</h2>
<p id='result'></p></div>
<div id="container"></div>

</div>
</div>
</body>
</html>

关于javascript - 我将如何附加结果值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45366007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com