答案 0 :(得分:3)
只需添加.change(handler)
$(() => {
$('#radio-manager').change((e) => {
$('#to-change').text(`You selected: ${e.target.value}`)
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<h1 id="to-change">Select a Show</h1>
<select class="radio-line" id="radio-manager" name=“show”>
<option value="Show1">Show 1 - May 9th 2017</option>
<option value="Show2">Show 2 - May 10th 2017</option>
<option value="Show3">Show 3 - May 11th 2017</option>
</select>
</form>
答案 1 :(得分:3)
您可以执行以下操作:
$(function() {
//Add event listener to dropdown with class radio-line
$('.radio-line').change(function() {
//Get the text of the selected option. Not its value
var text = $(this).find("option:selected").text();
//Update the text of h1
$('h1').text(text);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h1>Select a Show</h1>
<select class="radio-line" id="radio-manager" name=“show”>
<option value=“Show1“>Show 1 - May 9th 2017</option>
<option value=“Show2“>Show 2 - May 10th 2017</option>
<option value=“Show3”>Show 3 - May 11th 2017</option>
</select>
答案 2 :(得分:2)
使用.change
事件监听器:
$('#radio-manager').on('change', function() {
const val = $('#radio-manager').val();
$('h1').text(val);
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<h1 id="to-change">Select a Show</h1>
<select class="radio-line" id="radio-manager" name=“show”>
<option value="Show1">Show 1 - May 9th 2017</option>
<option value="Show2">Show 2 - May 10th 2017</option>
<option value="Show3">Show 3 - May 11th 2017</option>
</select>
</form>
&#13;
答案 3 :(得分:1)
您需要使用jQuery的change
事件。
$('#radio-manager').change(function() {
$('h1').text($(this).val());
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>Select a Show</h1>
<select class="radio-line" id="radio-manager" name=“show”>
<option value="Show1">Show 1 - May 9th 2017</option>
<option value="Show2">Show 2 - May 10th 2017</option>
<option value="Show3">Show 3 - May 11th 2017</option>
</select>
&#13;
答案 4 :(得分:1)
.change事件就是你要找的。此事件将允许您在选择项目更改时运行函数:
var h1 = $('.targetChange')
$('.target').change(function(e){
h1.text($(this).val())
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1 class="targetChange">
Hello
</h1>
<form>
<select class="target">
<option value="option 1 selected" selected="selected">Option 1</option>
<option value="option 2 selected">Option 2</option>
</select>
</form>
<div id="other">
Trigger the handler
</div>
答案 5 :(得分:0)
将id添加到h1标记(您想要更改其值),如下面的html
<h1 id='h1_head'>Select a Show</h1>
<select class='radio-line' id='radio-manager' name='show'>
<option value='Show1'>Show 1 - May 9th 2017</option>
<option value='Show2'>Show 2 - May 10th 2017</option>
<option value='Show3'>Show 3 - May 11th 2017</option>
</select>
然后将jquery放在脚本标记内。
$("#radio-manager").change(function(){
var dropdown = this;
var dropdownValue = $(dropdown).val();
console.log(dropdownValue);
$("#h1_head").text(dropdownValue);
});
上面的JQuery在&#39; Select&#39;改变了。 (如果没有被解雇,请将其放入文件准备就绪,即
$(document).ready(function(){
$("#radio-manager").change(function(){
var dropdown = this;
var dropdownValue = $(dropdown).val();
$("#h1_head").text(dropdownValue);
});
});