这是test.html文件,如下
$(document).ready(function(e) {
$("#get").click( function() {
$.ajax({
type: 'GET',
url: 'temp.html',
success: function(data){
$(".month").html(data);
}
});
});
$("#month").change( function() {
alert($(this).val());
});
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="get">Get Months</button>
<div class="month"></div>
&#13;
这是temp.html文件,如下所示
<select id="month">
<option>--Select Month--</option>
<option value='1'>Janaury</option>
<option value='2'>February</option>
<option value='3'>March</option>
<option value='4'>April</option>
<option value='5'>May</option>
<option value='6'>June</option>
<option value='7'>July</option>
<option value='8'>August</option>
<option value='9'>September</option>
<option value='10'>October</option>
<option value='11'>November</option>
<option value='12'>December</option>
</select>
&#13;
当用户点击按钮时,它会获得数月的下拉按钮 我只想在用户从下拉列表中更改月份时收到警报。我无法更改temp.html,因为它来自其他服务器。
答案 0 :(得分:1)
试试这个
$(document).on("change", "#month", function() {
alert($(this).val());
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="month">
<option>--Select Month--</option>
<option value='1'>Janaury</option>
<option value='2'>February</option>
<option value='3'>March</option>
<option value='4'>April</option>
<option value='5'>May</option>
<option value='6'>June</option>
<option value='7'>July</option>
<option value='8'>August</option>
<option value='9'>September</option>
<option value='10'>October</option>
<option value='11'>November</option>
<option value='12'>December</option>
</select>
&#13;