-3

大家好,我是 javascript 新手,我这辈子都无法让它在 html 中显示

<html>
  <head>
    <body>
      <script type="text/javascript" src="scripts/category.js"></script>
       <select><script>
        var makeModel = new DynamicOptionList("MAKE","MODEL","TYPE");
    makeModel.addDependentFields("MAKE2","MODEL2","TYPE2");

    makeModel.forValue("Ford").addOptions("Fiesta","Focus","Taurus"); // Add options if VALUE of option is selected
    makeModel.forText("Honda").addOptions("Civic","Accord","Prelude"); // Add these options if TEXT of option is selected

    makeModel.forValue("Ford").setDefaultOptions("Fiesta");
    makeModel.forText("Honda").setDefaultOptions("Accord");
    makeModel.forValue("Ford").forValue("Taurus").addOptions("2-door","4-door");

    makeModel.forField("MODEL").setValues("Focus","Taurus");
    makeModel.forField("TYPE").setValues("2-door");
    makeModel.forField("MODEL2").setValues("Civic","Prelude");

    makeModel.forValue("Toyota").addOptionsTextValue("Camry","10-CAMRY","Corolla","20-COROLLA","Celica","30-CELICA"); // Add options with values different from text
</script></select>
</body></head></html>

来自http://www.mattkruse.com/javascript/dynamicoptionlist/的代码示例 3

4

2 回答 2

0

首先,您应该知道,JavaScript 与 Java 是完全分开的!所以,顺便说一下,如果你想在 html 中编写一些 JavaScript 代码,你应该在你的<body></body>标签中使用 script 标签,如下例所示:

<script type="text/javascript"> // your javascript code here! </script>

作为一个选项,您可以添加外部 JavaScript 文件,并将其附加到您的脚本标签,如下例所示:

<script type="text/javascript" src="example.js"></script>

欲了解更多信息,请查看这个地方

于 2013-11-08T22:30:33.800 回答
0

您引用的示例使用了一个名为 DynamicOptionList.js 的附加库,您可以在此处找到该库。

根据文档BODY,您还需要通过在onLoad 属性(或从其他地方)调用 initDynamicOptionLists() 来初始化库。

于 2013-11-08T22:31:33.437 回答