ES6导出对象数组

时间:2018-08-29 17:39:28

标签: javascript ecmascript-6

尝试在Javascript ES6中导出对象数组:

settings.js

const elements = [
  {
    input: document.getElementById("name"),
    required: true,
    min: 1,
    max: 100,
    type: "alpha"
  },
  {
    input: document.getElementById("addr1"),
    required: true,
    min: 1,
    max: 100,
    type: "alphanumeric"
  }
];

export default elements;

validation.js

import elements from "./settings.js";

我总是会收到错误:

Uncaught SyntaxError: Unexpected identifier

index.html

<!DOCTYPE html>

    

<div id="form">
    <form action="">
        <label for="name">Name</label>
        <input type="text" id="name" name="name" placeholder="Your name..">
        <div class="error"></div>

        <label for="addr">Address 1</label>
        <input type="text" id="addr1" name="addr1" placeholder="Your first address..">
        <div class="error"></div>

        <label for="addr1">Address 2</label>
        <input type="text" id="addr2" name="addr2" placeholder="Your second address..">
        <div class="error"></div>

        <label for="city">City</label>
        <input type="text" id="city" name="city" placeholder="Your city..">
        <div class="error"></div>

        <label for="state">State</label>
        <select id="state" name="state">
            <option value="australia">Australia</option>
            <option value="usa">USA</option>
        </select>
        <div class="error"></div>

        <label for="zip">Zip Code</label>
        <input type="text" id="zip" name="zip" placeholder="Your zip code..">
        <div class="error"></div>

        <input type="button" id="confirm" value="Ok">
        <input type="button" id="cancel" value="Cancel">
    </form>
</div>

<script src="./validation.js"></script>
</body>

</html>

无法找出原因!

0 个答案:

没有答案