firing a jQuery change function at document ready

后端 未结 4 1472
醉酒成梦
醉酒成梦 2021-02-02 12:01

My change function allows users to switch from country to country and get different text and features. It works when changing country selections. But at initial page load, it do

4条回答
  •  旧时难觅i
    2021-02-02 12:32

    This usually is made as:

    function onChange ()
    {                                                                               
        switch ($('input[name=country]:checked').val())
        ....
    }
    
    $('input[name=country]').change(onChange); // 1. attach it as event handler.
    onChange();                                // 2. call it first time.
    

提交回复
热议问题