如何从数据清单中获取价值

时间:2019-04-12 17:59:00

标签: javascript jquery html html5

我需要从数据列表中获取值吗?

当前,我为2个参数定义了yoursign和friendsign

例如,如果我为您的手势选择白羊座,为friendSign选择狮子座,则需要同时获取两者并传递给函数

    <body>
    <form id="Match"></form>

<label for="yourSignList">your sign:</label><br /><input list="yourSignList" name="sign1" required><br />
<datalist id="yourSignList">
    <option value="Aries">
    <option value="taurus">
    <option value="Gemini">
    <option value="Cancer">
    <option value="Leo">
    <option value="Virgo">
    <option value="Libra">
    <option value="Scorpio">
    <option value="Saggitarius">
    <option value="Capricon">
    <option value="Aquarius">
    <option value="Pisces">
</datalist>



<label for="friendSignList">your friend sign:</label><br /><input list="friendSignList" name="sign2" required><br />
<datalist id="friendSignList">
    <option value="Aries">
    <option value="taurus">
    <option value="Gemini">
    <option value="Cancer">
    <option value="Leo">
    <option value="Virgo">
    <option value="Libra">
    <option value="Scorpio">
    <option value="Saggitarius">
    <option value="Capricon">
    <option value="Aquarius">
    <option value="Pisces">
</datalist>



<button type='submit' onclick="Match()">Done</button><br>
<label for="output">התאמה: </label><output id='output'></output>
<form />

<script>
    function Match() {

      const signYours = $("yourSignList").val();
      const signFriend = $("friendSignList").val();

        $("#output").val(answer(signYours, signFriend));
    }

2 个答案:

答案 0 :(得分:0)

这对我有用:

   function Match() {
        var signYours = $("input[name='sign1']").val();
        var   signFriend = $("input[name='sign2']").val();

        $("#output").val(answer(signYours, signFriend));
    }

答案 1 :(得分:-1)

尝试此代码可能类似于

dept