當我按下按鈕時,我想顯示所有用戶輸入從一行到一行(每行之間有空格)。我已經讓按鈕作業了,它確實顯示了用戶輸入,但不是我想要的方式。
它是如何顯示的:
one
two
three
我希望它如何顯示:
one two three
我發現的只是如何顯示我什至沒有使用的python。我的代碼應該是什么樣子?(順便說一句,我不是 JavaScript 專家或比這更難的東西;從其他地方得到 JS)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="" />
<title>Document</title>
</head>
<body>
<form action="#">
<h1>Cert Form</h1>
<div>
<label for="typeOfCSR">Choose the type of...</label>
<select name="typeOfCSR" id="typeOfCSR">
<option value="">Select an Option </option>
<option value="One">One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
</select>
</div>
<div>
<label for="CN"> Enter the CN...</label>
<textarea cols="100" rows="1" id="CN"></textarea>
</div>
<div>
<label for="FQDN"> Enter the FQDN...</label>
<textarea cols="50" rows="5" id="FQDN"></textarea>
</div>
<div>
<label for="alternateName"> Enter the alt name</label>
<textarea cols="50" rows="5" id="altName"></textarea>
</div>
<div>
<label for="nameOfCert"> Enter the name...</label>
<textarea cols="50" rows="5" id="nameOfCert"></textarea>
</div>
</div>
<button type="button" id="review">Generate String</button>
<button type="submit"> Submit </button>
</form>
<br/>
<div id="result" style="border: 3px solid black;"> Result will show here</div>
<script>
const btn = document.getElementById('review');
btn.addEventListener('click',()=>{
let typeOfCSR = document.getElementById('typeOfCSR').value;
let CN = document.getElementById('CN').value;
let FQDN = document.getElementById('FQDN').value;
let altName = document.getElementById('altName').value;
let nameOfCert = document.getElementById('nameOfCert').value;
document.getElementById('result').innerHTML = typeOfCSR "<br/>" CN "<br/>" FQDN "<br/>" altName "<br/>" nameOfCert;
})
</script>
</body>
</html>
uj5u.com熱心網友回復:
您<br/>在每個條目之間都有,這使它們顯示在單獨的行上,用空格替換它。innerHTML在處理用戶的輸入時,你永遠不應該使用,textContent而是使用。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="" />
<title>Document</title>
</head>
<body>
<form action="#">
<h1>Cert Form</h1>
<div>
<label for="typeOfCSR">Choose the type of...</label>
<select name="typeOfCSR" id="typeOfCSR">
<option value="">Select an Option </option>
<option value="One">One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
</select>
</div>
<div>
<label for="CN"> Enter the CN...</label>
<textarea cols="100" rows="1" id="CN"></textarea>
</div>
<div>
<label for="FQDN"> Enter the FQDN...</label>
<textarea cols="50" rows="5" id="FQDN"></textarea>
</div>
<div>
<label for="alternateName"> Enter the alt name</label>
<textarea cols="50" rows="5" id="altName"></textarea>
</div>
<div>
<label for="nameOfCert"> Enter the name...</label>
<textarea cols="50" rows="5" id="nameOfCert"></textarea>
</div>
</div>
<button type="button" id="review">Generate String</button>
<button type="submit"> Submit </button>
</form>
<br/>
<div id="result" style="border: 3px solid black;"> Result will show here</div>
<script>
const btn = document.getElementById('review');
btn.addEventListener('click',()=>{
let typeOfCSR = document.getElementById('typeOfCSR').value;
let CN = document.getElementById('CN').value;
let FQDN = document.getElementById('FQDN').value;
let altName = document.getElementById('altName').value;
let nameOfCert = document.getElementById('nameOfCert').value;
document.getElementById('result').textContent = typeOfCSR " " CN " " FQDN " " altName " " nameOfCert;
})
</script>
</body>
</html>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/450480.html
標籤:javascript html 形式 输入 输出
上一篇:我怎樣才能使每個if分別用完
