私はうまく動作するこのjQueryスクリプトを持っています:
$("select").change(function () {
var finalPrice = 0;
$("select option:selected").each(function () {
if ($.cookie('descuentoGen') != null){
finalPrice = Math.floor(precios[$(this).index()]*$.cookie('descuentoGen'));
} else{
finalPrice = precios[$(this).index()];
}
});
$("#precioFinal").text(finalPrice);
})
.trigger('change');
ご覧のとおり、ユーザーが で別のオプションを選択すると、単に何らかのアクションを実行しますselect
。
今、別のスクリプトでこれを呼び出しています:
document.getElementById('selectFoods').selectedIndex = t;
これは、選択したオプションを実際に変更するため、正常に機能します。問題は、選択したオプションをこのように変更する理由であり、最初の jQuery スクリプトからのアクションが実行されないことです。
これを回避する方法はありますか、それとも他のスクリプトで jQuery スクリプトの動作を複製する必要がありますか?