1

我已经通过 jQuery 设置了一个 div 来显示和隐藏项目的悬停。在 div 中我有下拉菜单,但是当我单击选择列表并将鼠标悬停在选项列表上时,选择菜单会立即关闭。

jQuery:

        <script type='text/javascript'>//<![CDATA[ 
    $(window).load(function(){

        $(".tiptext").mouseover(function() {
            $(this).children(".description").show();
        }).mouseout(function() {
            $(this).children(".description").hide();
        });


    });//]]>  
    </script>

HTML:

    <div class="description" style="display: none;">

                <div id="tab1">
                    <h2>Calendar Use</h2>
                    <p>Available dates are marked in white, those unavailable are black. The holiday villa is available from 4:00pm on the day of arrival and needs to be vacated by 10:00am on the day of departure. If you have earlier flight arrival times kindly contact us directly.</p>
                </div>

                <div id="tab2">
                    <h2>Check Availability</h2>
                    <br><p>Arrival Date</p>
                    <div id="calendar-titles"><span class="day-t">day</span><span class="month-t">month</span><span class="year-t">year</span></div>

<form method="post" action="">

                        <div id="calendar-container"><select id="year2Sel" name="year2Sel" onchange="showRSS(document.getElementById('field2').value"></select><select id="monthSel" name="monthSel" onclick="showRSS(document.getElementById('field2').value, document.getElementById('yearSel').value, this.value, document.getElementById('daySel').value )"><option value="0">January</option><option value="1">February</option><option value="2">March</option><option value="3">April</option><option value="4">May</option><option value="5">June</option><option value="6">July</option><option value="7">August</option><option value="8">September</option><option value="9">October</option><option value="10">November</option><option value="11">December</option></select><select id="daySel" name="daySel" onchange="showRSS(document.getElementById('field2').value, document.getElementById('yearSel').value, document.getElementById('monthSel').value, this.value )"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option></select></div>
<select id="yearSel" name="yearSel" onchange="showRSS(document.getElementById('field2').value, document.getElementById('yearSel').value, document.getElementById('monthSel').value, document.getElementById('daySel').value)">
                            <option value="2013">2013</option>
                            <option value="2014">2014</option>
                        </select>

<div id="avail-left">
<p>No of Nights</p>
<span>min stay: 7 nights</span>

                        <input type="text" id="field2" name="nights" onkeyup="showRSS(this.value, document.getElementById('yearSel').value, document.getElementById('monthSel').value, document.getElementById('daySel').value)" value="" alt="Test" onkeypress="return isNumberKey(event)" onchange="isValid();">

</div>
<div id="avail-right">
<p>Est. Rate</p>
<div id="rssOutput"></div></div>

<input type="submit" value="Enquire" name="submit" class="enquirebtn">
                    </form>

                    <br>



                </div>

                <div id="tab3">
                    <iframe width="243px" height="221px" src="/calendar/index.php" frameborder="0" border="0" style="border:0px;"></iframe>
                </div>

            </div>

有人对如何解决这个问题有任何建议吗?

4

1 回答 1

1

使用mouseenterandmouseleave代替mouseoverandmouseout

如果用户将鼠标悬停在嵌套在给定元素中的元素之上或之外,则针对给定元素触发 mouseover 和 mouseout 事件。

    $(".tiptext").mouseenter(function() {
        $(this).children(".description").show();
    }).mouseleave(function() {
        $(this).children(".description").hide();
    });

如果你想知道这些之间的区别,通过这个链接会很有帮助

于 2013-01-22T10:47:14.610 回答