簡體   English   中英

如何使用 img(即 href 鏈接)和單選按鈕(值或 id)制作一個函數並轉到下一頁

[英]how to make a function out of img (which is href link ) and radio button (value or id) and goes to the next page

我有這個代碼:

 <div id="section"> <h3 for="horoscope">choose horoscope</h3> <table> <tr> <td> <input type="radio" name="period" value="week" id="week" checked/> <b>'weekly</b> <td> <input type="radio" name="period" value="month" id="month" /> <b>monthly</b> <td> <input type="radio" name="period" value="year" id="year"> <b>yearly</b> </td> </tr> </table> <table id="horoscope" cellpadding="10"> <td><a href="Aries.html"><img src="https://cdn.pixabay.com/photo/2012/04/18/01/12/aries-36388_960_720.png" height="50px" width="53px" alt="aries" /></a> </td> <td> <a href="Taurus.html"><img src="https://cdn.pixabay.com/photo/2012/04/18/01/14/taurus-36397_960_720.png" height="50px" width="48px" alt="Taurus" /></a> </td> <td> <a href="Gemini.html"><img src="https://cdn.pixabay.com/photo/2012/04/18/01/13/gemini-36391_960_720.png" height="50px" width="49px" alt="Gemini" /></a> </td> </tr> </table>

所以我想做一個函數來獲取周期(例如每月)和符號(例如金牛座),在下一頁上它將轉到金牛座頁面和每月的位置。

另一個例子:我選擇每周和白羊座->在下一頁->每周白羊座

怎么做?

就這樣做

你的 HTML 代碼

<div id="section">
        <h3 for="horoscope">choose horoscope</h3>
        <table>
            <tr>
                <td>
                    <input type="radio" name="period" value="week" id="week" checked/>
                    <b>'weekly</b>

                <td>
                    <input type="radio" name="period" value="month" id="month"/>
                    <b>monthly</b>

                <td>
                    <input type="radio" name="period" value="year" id="year">
                    <b>yearly</b>
                </td>
            </tr>
        </table>

        <table id="horoscope" cellpadding="10">
            <tr>
                <td><img onclick="redirect('Aries.html')"
                         src="https://cdn.pixabay.com/photo/2012/04/18/01/12/aries-36388_960_720.png" height="50px"
                         width="53px" alt="aries"/></td>
                <td><img onclick="redirect('Taurus.html')"
                         src="https://cdn.pixabay.com/photo/2012/04/18/01/14/taurus-36397_960_720.png" height="50px"
                         width="48px" alt="Taurus"/></td>
                <td><img onclick="redirect('Gemini.html')"
                         src="https://cdn.pixabay.com/photo/2012/04/18/01/13/gemini-36391_960_720.png" height="50px"
                         width="49px" alt="Gemini"/></td>
            </tr>
        </table>
    </div>

你的劇本

<script>
function redirect(link) {
    window.location.href=link+"#"+$("input[name='period']:checked").val();
}
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM