Jquery execute onchange event on onload

后端 未结 6 1314
悲哀的现实
悲哀的现实 2020-12-01 16:02

I have a function that on change event run the post actions.

$(\"select#marca\").change(function(){
    var marca = $(\"select#marca option:selected\").attr(         


        
6条回答
  •  遥遥无期
    2020-12-01 16:16

    To call onload, you can try jQuery:

     $(document).ready(function(){
     onchange();// onload it will call the function
         });
    

    Write your onchange function like this, so this will be called when onchange occurs,

    function onchange(){
        var marca = $("select#marca option:selected").attr('value');
        $("select#modello").html(attendere);
        $.post("select.php", {id_marca:marca}, function(data){
        $("select#modello").html(data);
    });
    

提交回复
热议问题