HTML 如何在每行之间显示 space 的所有用户输入
HTML How to display all user input on single line with space inbetween each
当我按下一个按钮时,我想在一行中显示所有用户输入(每行之间有 space)。
我已经让按钮正常工作,它确实显示了用户输入,但不是我想要的方式。
显示方式:
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>
每个条目之间有 <br/>
,这使得它们显示在不同的行中,请将其替换为 space。在处理用户输入时,你不应该使用 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>
当我按下一个按钮时,我想在一行中显示所有用户输入(每行之间有 space)。 我已经让按钮正常工作,它确实显示了用户输入,但不是我想要的方式。
显示方式:
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>
每个条目之间有 <br/>
,这使得它们显示在不同的行中,请将其替换为 space。在处理用户输入时,你不应该使用 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>