猿问

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

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


目前,我为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));

    }


撒科打诨
浏览 158回答 2
2回答

红糖糍粑

试试这个代码可能像$("#friendSignList").find("option").each(function(e,i){&nbsp;&nbsp;&nbsp;&nbsp;console.log(&nbsp;e,&nbsp;i&nbsp;);});

aluckdog

这对我有用:&nbsp; &nbsp;function Match() {&nbsp; &nbsp; &nbsp; &nbsp; var signYours = $("input[name='sign1']").val();&nbsp; &nbsp; &nbsp; &nbsp; var&nbsp; &nbsp;signFriend = $("input[name='sign2']").val();&nbsp; &nbsp; &nbsp; &nbsp; $("#output").val(answer(signYours, signFriend));&nbsp; &nbsp; }
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答