选项值自动运行javascript页面加载

时间:2017-10-31 00:03:43

标签: javascript

所以当我加载页面时,第1周会自动选择好的选项,但是直到我手动选择一个选项时,javascript才会运行。我希望javascript在第1周自动加载,但我不知道该怎么做。

 <section class="Schedule">
            <form name = "form_schedule" action = "">
                <select id = "s1" name = "s1" onchange = "schedule('this.form')">
                    <option value = "Week 1" selected> Week 1 </option>
                    <option value = "Week 2"> Week 2 </option>
                    <option value = "Week 3"> Week 3 </option>
                    <option value = "Week 4"> Week 4 </option>
                    <option value = "All Weeks"> All Weeks </option>
                </select>
            </form>
                <h2> Schedule </h2>           
                    <table border = "2" id = "League_Schedule">
                        <tr>
                            <th> Home</th> 
                            <th> Result </th>               
                            <th> Away </th>
                        </tr>
                    </table>
        </section>

1 个答案:

答案 0 :(得分:0)

您可以添加onload功能:

<script>window.onload = schedule('this.form')</script>

只需将它放在关闭身体标签之前。