好的,我想这全都归结为:我该如何改善这段代码...
<br><br>
<select id="newText">
<option value="url1">tool_ver1</option>
<option value="url2">tool_ver2</option>
<option value="url2" selected >tool_ver3</option>
</select>
<br><br>
<button type="submit">Retrieve New Release App Options</button>
<br><br>
要填充以下文本区域...
<div class="textInput spacer">
<h2>New Release App Options</h2>
<textarea id="newText"></textarea>
</div>
最后,textarea需要填充为newText选择的所有url的内容。我无法使用“提交”按钮来完成我希望/期望的事情。
答案 0 :(得分:1)
使用jQuery,选择元素并使用val
方法。在纯js中,查询元素并使用value
成员。
//jQuery
$(document).ready(function(){
$("textarea#mytextarea").val("My value");
});
//OR pure js
document.getElementById('mytextarea').value = 'My value';
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id='mytextarea'></textarea>
答案 1 :(得分:1)
这是使用不带jquery的纯js的简单答案。 您可以根据需要对其进行修改,以进行“提交”操作,但我可以进行“更改”。
const select = document.getElementById('select')
const newText = document.getElementById('newText')
select.addEventListener("change", e => {
console.log(e.target.value)
newText.value = e.target.value
})
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<select id="select">
<option value="url1">tool_ver1</option>
<option value="url2">tool_ver2</option>
<option value="url3" selected >tool_ver3</option>
</select>
<button type="submit">Retrieve New Release App Options</button>
<div class="textInput spacer">
<h2>New Release App Options</h2>
<textarea id="newText"></textarea>
</div>
</body>
</html>
答案 2 :(得分:0)
我认为您正在挂断电话,因为您的
https://jsfiddle.net/bytebodger/zct0po47/
$(document).ready(function(){
const currentValue = $('#newText').val();
$('#selectedOption').empty().append(currentValue);
$('#newText').on('change', function(event) {
const currentValue = $('#newText').val();
$('#selectedOption').empty().append(currentValue);
});
});
答案 3 :(得分:-1)
为了关闭,最终对我有用。感谢所有提供帮助的人-非常感谢!
<body>
<h1 class="top"> Check application option default settings between two releases</h1>
<div class="top"><br>
<button type="submit">Select Release #1</button>
<select id="selectedBaseRelease">
<option value="https://wwwin/~ckennedy/releases/K-2015.06.AppOp.Defaults.txt" selected >ICC2_K-2015.06</option>
<option value="https://wwwin/~ckennedy/releases/L-2016.03.AppOp.Defaults.txt">ICC2_L-2016.03</option>
<option value="https://wwwin/~ckennedy/releases/M-2016.12.AppOp.Defaults.txt">ICC2_M-2016.12</option>
<option value="https://wwwin/~ckennedy/releases/N-2017.09.AppOp.Defaults.txt">ICC2_N-2017.09</option>
<option value="https://wwwin/~ckennedy/releases/O-2018.06.AppOp.Defaults.txt">ICC2_O-2018.06</option>
</select>
<br><br>
<button type="submit">Select Release #2</button>
<select id="selectedNewRelease">
<option value="https://wwwin/~ckennedy/releases/K-2015.06.AppOp.Defaults.txt">ICC2_K-2015.06</option>
<option value="https://wwwin/~ckennedy/releases/L-2016.03.AppOp.Defaults.txt" selected >ICC2_L-2016.03</option>
<option value="https://wwwin/~ckennedy/releases/M-2016.12.AppOp.Defaults.txt">ICC2_M-2016.12</option>
<option value="https://wwwin/~ckennedy/releases/N-2017.09.AppOp.Defaults.txt">ICC2_N-2017.09</option>
<option value="https://wwwin/~ckennedy/releases/O-2018.06.AppOp.Defaults.txt">ICC2_O-2018.06</option>
</select>
<br><br>
</div>
<div class="top">
<strong>Context size (optional):</strong> <input type="text" id="contextSize" value="" />
</div>
<div class="textInput spacer">
<h2>Release #1 App Option Defaults</h2>
<textarea class="textbox" id="baseText"></textarea>
<script>
$(document).ready(function(){
const currentBaseValue = $('#selectedBaseRelease').val();
$('#baseText').empty().append(currentBaseValue);
$('#selectedBaseRelease').on('change', function(event) {
const currentBaseValue = $('#selectedBaseRelease').val();
$('#baseText').empty().load(currentBaseValue)
});
});
</script>
</div>
<div class="textInput spacer">
<h2>Release #2 App Option Defaults</h2>
<textarea class="textbox" id="newText"></textarea>
<script>
$(document).ready(function(){
const currentNewValue = $('#selectedNewRelease').val();
$('#newText').empty().append(currentNewValue);
$('#selectedNewRelease').on('change', function(event) {
const currentNewValue = $('#selectedNewRelease').val();
$('#newText').empty().load(currentNewValue)
});
});
</script>
</div>
<div class="viewType">
<input type="radio" name="_viewtype" id="sidebyside" onclick="diffUsingJS(0);" /> <label for="sidebyside">Side by Side Diff</label>
<input type="radio" name="_viewtype" id="inline" onclick="diffUsingJS(1);" /> <label for="inline">Inline Diff</label>
</div>
<div id="diffoutput"> </div>
</body>