我正试图在页面加载时调用fwre-sel-region_id的更改方法。通常,在选择id的选项select更改后调用此方法。这不适用于我,因为select id只有一个有效的选项。所以我想通过javascript更改select id后调用它。我现在成功地改变了选择id的索引,我希望它能调用fwre-sel-region_id的改变方法。
<script type="text/javascript">
setTimeout(function() {
if ($('fwre-sel-region_id')) {
$('fwre-sel-region_id').addEvent('change', function() {
$('fwre-sel-city_id').options.length = 0;
if (this.value == '(add-value)') return;
var img = new Element('img', {
'id': 'fwre-wait-region',
'style' : 'margin:0;padding:0;',
'src': '/administrator/components/com_fwrealestatelight/assets/images/spinner.gif'
});
img.inject($('fwre-sel-city_id'), 'after');
new Request.JSON({
url: '/properties?format=raw&task=loadDictionary',
onSuccess: function(obj) {
if ($('fwre-wait-region')) $('fwre-wait-region').dispose();
if (obj.msg) {
alert(obj.msg);
} else if (obj.data) {
for (var i = 0; i < obj.data.length; i++) {
var op = new Element('option', {
'value': obj.data[i].id
});
op.inject($('fwre-sel-city_id'));
op.innerHTML = obj.data[i].name;
}
}
$('fwre-sel-city_id').fireEvent('change');
}
}).get({'parent_id':$('fwre-sel-region_id').value,'dname':'city_id'});
});
}
}, 500);
我正在尝试使用此脚本调用上面的方法
<script type="text/javascript" >
window.addEvent('load', function(){
var country = document.id('fwre-sel-country_id');
var region = document.id('fwre-sel-region_id');
$(country).selectedIndex = 1;
region.fireEvent('change');
});
</script>
我的脚本都在文件和html的脚本下面,但是当region.fireEvent('change');执行它不会让它回到第一种方法。为什么会这样?