我需要处理所选选项的警报事件。
using System;
例如,如果我选择“B”选项,我想要像“选择选项是:B”等警告......
谢谢!
答案 0 :(得分:0)
尝试一次它的工作。
function myFunction() {
var x = document.getElementById("mySelect").value;
alert('You Selected'+' '+x);
}

<p>Select a any value in list.</p>
<select id="mySelect" onchange="myFunction()">
<option value="1">A
<option value="2">B
<option value="3">C
<option value="4">D
</select>
&#13;
答案 1 :(得分:0)
工作示例:(这是一个jQuery示例,主要使用选择器和事件)
// Wait for DOM load
$(document).ready(function() {
// Binding change event to the <select>
$('#my_select').change(function() {
// Saving the HTML corresponding to the value selected
$selected = $('#my_select option:selected').text();;
// Debugging actual selection DOM-node on console
console.log($('#my_select option:selected'));
// Showing the message
alert("Chosen option is: " + $selected);
});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- I have set an ID to identify you select -->
<select id="my_select">
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
<option value="3">D</option>
</select>
&#13;
一些官方jQuery的文档链接: