Onchange是javascript和jquery代码的未捕获混合

Onchange is uncaught mix of javascript and jquery code

本文关键字:混合 代码 javascript jquery Onchange      更新时间:2023-09-26

代码应该基于javascript中的select选项do checkseason()函数,并进行相应的调整,否则(目前)什么都不做。我现在得到的错误是Uncaught ReferenceError:checkseason没有在select value="checkseason();"行上定义

   echo '<form id="first_form" action="#" method="POST" style="border: 0; margin: 0;">';
                        echo '<input type="hidden" value="'.$formid.'" name="formid">';
                        echo '<h1>Season, Patch version & amount of champions</h1>';
                        echo '<select id="season" onchange="checkseason();">';
                            echo '<option value="newseasons" selected>Season 3+</option>';
                            echo '<option value="oldseasons">Season 1, 2</option>';
                        echo '</select>';
                        echo '<input id="patch" type="text" name="patch" placeholder="e.g. 4.20" required autofocus><br/>';
                        echo '<input placeholder="Number of Champions" value="1" type="number" name="champ_number" min="1" max="20" required><br/>';
                        echo '<input type="submit" value="next">';
                    echo '</form>'; 

和Javascript/Jquery部分代码

$(document).ready(function(){
                function checkseason(){
                    d = document.getElementById("season").value;
                        if(d==='newseasons'){
                            $('#first_form').validate({
                                rules: {
                                    patch: {
                                        required: true,
                                        minlength: 4,
                                        remote: {
                                            url: "../checkpatch.php",
                                            type: "post"
                                            }
                                        }
                                    },
                                messages: {
                                    patch: {
                                        required: "Please enter patch version.",
                                        remote: "Patch with this number already exists.",
                                        minlength: "Please enter 3 numbers"
                                        }
                                    },
                            });
                        $.mask.definitions['~'] = "[+-]";
                        $.mask.definitions['x'] = '[0-9]';
                        $.mask.definitions['*'] = '[-A-Za-z0-9._'''/?&=~]';
                        $("#patch").mask("x.xx", {
                            placeholder: ""
                        });
                    }
                    else if(d==='oldseasons'){}
                }
     });

您需要删除$(document).ready(function(){});部分,以便在加载页面之前加载函数。