如果未检查此页面上的复选标记,我试图显示一条消息 - https://www.hawaiidiscount.com/rental-cars/oahu/honolulu-airport.htm
看看它的位置“我知道Alamo有额外费用,在拿车时直接向柜台支付给Alamo。”
在静态页面上,下面的脚本可以正常工作(例如,如果您下载页面并将代码放在正文中)。 但是当页面生效时,它无法正常工作。
<script> $('#dnn_ctr367_CartQuickView_anchBookNow').click(function () { if (!$('.cartcheckbox').is(':checked')) { alert('Please check the box - I\'m aware Alamo has additional fees, paid directly to Alamo at the counter when picking up the vehicle.'); return false; } }); </script>知道什么可能是错的吗?
编辑:当您单击现在的书籍按钮时,显示在购物车顶部的文本(如果您没有提供任何所需信息)。 因此,该文本似乎是忽略上述脚本的程序的一部分。 有没有办法让我的脚本在另一个之前激活,所以如果你点击绿色按钮,你会立即看到弹出消息?
I am trying to show a message if the checkmark on this page is not checked - https://www.hawaiidiscount.com/rental-cars/oahu/honolulu-airport.htm
See where it says "I'm aware Alamo has additional fees, paid directly to Alamo at the counter when picking up the vehicle."
On a static page the script below works correctly (for example if you download the page and place the code in the body). But when the page is live, it is not working.
<script> $('#dnn_ctr367_CartQuickView_anchBookNow').click(function () { if (!$('.cartcheckbox').is(':checked')) { alert('Please check the box - I\'m aware Alamo has additional fees, paid directly to Alamo at the counter when picking up the vehicle.'); return false; } }); </script>Any idea what might be wrong?
EDIT: When you click on the book now button there is text that appears on top of the cart (that's in case you didn't put any of the required information). So it seems this text is part of a program that ignores the script above. Is there a way to make my script to activate before the other one so if you click the green button you will right away see the pop up message?
最满意答案
这是因为$('.cartcheckbox')不是一个复选框,它是一个包含复选框的范围
尝试将其更改为复选框的ID(如果页面中只有一个复选框,则input[type="checkbox"] 。
如:
$('#dnn_ctr367_CartQuickView_anchBookNow').on('click', function () { // update selector below if (!$('input[type="checkbox"]').is(':checked')) { alert('Please check the box - I\'m aware Alamo has additional fees, paid directly to Alamo at the counter when picking up the vehicle.'); return false; } });如果页面上有多个复选框,请尝试将其更改为
if (!$('.cartcheckbox').find('input[type="checkbox"]').is(':checked')) {...}仅选择相关span内的复选框
更新下面的代码以包含触发按钮
$(function() { $('#dnn_ctr367_CartQuickView_anchBookNow').on('click', function() { // updated selector below if (!$('.cartcheckbox').find('input[type="checkbox"]').is(':checked')) { alert('Please check the box - I\'m aware Alamo has additional fees, paid directly to Alamo at the counter when picking up the vehicle.'); return false; } else { alert('checkbox is checked'); } }); });<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <span class="cartcheckbox"><input id="dnn_ctr367_CartQuickView_ucCollector_I'mawareAlamohasadditionalfees,paiddirectlytoAlamoatthecounterwhenpickingupthevehicle." type="checkbox" name="dnn:ctr367:CartQuickView:ucCollector:I'mawareAlamohasadditionalfees,paiddirectlytoAlamoatthecounterwhenpickingupthevehicle."></span> <br/> <div align="center"> <a id="dnn_ctr367_CartQuickView_anchBookNow" style="TEXT-DECORATION: none" href="#"> <button> <div class="TBook">Book Now</div> </button> </a> </div>It's because $('.cartcheckbox') is not a checkbox, it's a span containing the checkbox
Try changing it to the id of the checkbox (or input[type="checkbox"] if you only have one checkbox in the page.
As in:
$('#dnn_ctr367_CartQuickView_anchBookNow').on('click', function () { // update selector below if (!$('input[type="checkbox"]').is(':checked')) { alert('Please check the box - I\'m aware Alamo has additional fees, paid directly to Alamo at the counter when picking up the vehicle.'); return false; } });If you have more than one checkbox on the page, try changing it to
if (!$('.cartcheckbox').find('input[type="checkbox"]').is(':checked')) {...}to select only the checkbox inside your relevant span
Updated code below to include trigger button
$(function() { $('#dnn_ctr367_CartQuickView_anchBookNow').on('click', function() { // updated selector below if (!$('.cartcheckbox').find('input[type="checkbox"]').is(':checked')) { alert('Please check the box - I\'m aware Alamo has additional fees, paid directly to Alamo at the counter when picking up the vehicle.'); return false; } else { alert('checkbox is checked'); } }); });<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <span class="cartcheckbox"><input id="dnn_ctr367_CartQuickView_ucCollector_I'mawareAlamohasadditionalfees,paiddirectlytoAlamoatthecounterwhenpickingupthevehicle." type="checkbox" name="dnn:ctr367:CartQuickView:ucCollector:I'mawareAlamohasadditionalfees,paiddirectlytoAlamoatthecounterwhenpickingupthevehicle."></span> <br/> <div align="center"> <a id="dnn_ctr367_CartQuickView_anchBookNow" style="TEXT-DECORATION: none" href="#"> <button> <div class="TBook">Book Now</div> </button> </a> </div>
更多推荐
发布评论