加载时,Javascript选择菜单onchange
我正在使用选择菜单:加载时,Javascript选择菜单onchange,javascript,jquery,forms,firefox,selected,Javascript,Jquery,Forms,Firefox,Selected,我正在使用选择菜单: <select id="form_frame1" name="frame1" onchange="getChart(this);"> <option value="area_chart_google" >Area Chart</option> <option value="area_chart_2" selected="selected">Stacked Chart</option> </select
<select id="form_frame1" name="frame1" onchange="getChart(this);">
<option value="area_chart_google" >Area Chart</option>
<option value="area_chart_2" selected="selected">Stacked Chart</option>
</select>
问题是,一旦我加载了页面,我会得到:区域\图表\谷歌:这甚至不是以前选择的选项!有两件事我不明白:
jQuery(function() {
if (localStorage.getItem('form_frame1')) {
jQuery("#form_frame1 option").eq(localStorage.getItem('form_frame1')).prop('selected', true);
jQuery("#form_frame1 option").change();
}
jQuery("#form_frame1").on('change', function() {
localStorage.setItem('form_frame1', jQuery('option:selected', this).index());
});
});
如果您实际使用的是jquery,那么为什么不试试呢
$('#form_frame1').change(function(){
getChart($('#form_frame1').val());
});
当您刷新页面时,它将自动选择第一个选项。请查看此小提琴。 使用如下
$(document).ready(function() {
$('#form_frame1').change(function() {
alert('Hi');
});
})) 我在您的代码中没有看到任何jQuery。另外,您的页面中是否有其他JavaScript没有显示在这里?除非您以某种方式触发它,否则它不会启动..您是对的,我发现了一个导致问题的Jquery。谢谢,但在我第一次加载页面时也会发生这种情况。谢谢
$(document).ready(function() {
$('#form_frame1').change(function() {
alert('Hi');
});