简体   繁体   English

实施预制Java脚本时遇到问题

[英]Problems Implementing a Premade Javascript

I would first like to state that I started learning HTML 5 days ago, and therefore I am very new to everything. 我首先要说的是,我是在5天前开始学习HTML的,因此我对所有事物都陌生。

I am trying to implement the code given here: http://jsfiddle.net/NFXzn/9/ . 我正在尝试实现此处给出的代码: http : //jsfiddle.net/NFXzn/9/

But for some reason the dropdown menu is blank. 但是由于某种原因,下拉菜单为空白。 I have uploaded my code here: http://gbrowse2014.biology.gatech.edu/viru.html 我已经在这里上传了我的代码: http : //gbrowse2014.biology.gatech.edu/viru.html

Since I did not make the code, I am assuming the problems lies with how I implemented the code (specifically the javascript). 由于我没有编写代码,因此我假设问题在于实现代码的方式(特别是javascript)。 I have narrowed the problem down to one particular function: 我已将问题缩小到一个特定的功能:

$.each(g_Vehicle, function(index) {
var iYear = g_Vehicle[index].Year;
if ($.inArray(iYear, g_YearsArray) == -1) {
    g_YearsArray.push(iYear);
}
});

I am using firefox, and I have gone through www.w3schools.com to look for implementation tips, but I have not corrected the problem. 我正在使用firefox,并且已经通过www.w3schools.com查找实现技巧,但是我没有纠正此问题。

On a sidenote, does anyone know how to change the code to use the dropdown-checkboxes instead of the dropboxes? 在旁注中,是否有人知道如何更改代码以使用dropdown-checkbox而不是dropbox?

That loop is working fine. 该循环工作正常。 The problem is that you're running the code before your select is loaded, so nothing is being appended to the page. 问题是您在加载select之前正在运行代码,因此页面上没有任何内容。 Either wrap your code in $(document).ready( function() { ... }); 将代码包装在$(document).ready( function() { ... }); , or move your <script> blocks to the bottom of the page (after the HTML has completely loaded). ,或将<script>块移动到页面底部(在HTML完全加载之后)。

http://learn.jquery.com/using-jquery-core/document-ready/ http://learn.jquery.com/using-jquery-core/document-ready/

(On the top-left corner of the jsFiddle page, you'll see a dropdown which displays onLoad -- which is automatically doing that job for you. Your page as it stands is the equivalent of No wrap - in <head> -- not what you want.) (在jsFiddle页面的左上角,您会看到一个下拉列表,其中显示了onLoad ,它会自动为您完成这项工作。您的页面就等于No wrap - in <head> -不是你想要的。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM