【发布时间】:2012-04-30 15:33:35
【问题描述】:
When one or fewer checkboxes are selected and you click the Compare tours button, a popup should appear.但是,此功能仅适用于 Chrome。我该怎么做才能让它在 Firefox 和 IE 中运行?
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder" runat="Server">
<script type="text/javascript">
$(document).ready(function () {
var selectedCheckboxes = $("input:checkbox[id$=Select]");
$("[id*=CompareTop]").click(function() {
if (selectedCheckboxes.filter(":checked").length <= 1) {
event.preventDefault();
alert("Please select at least 2 tours to compare.");}
});
selectedCheckboxes.change(function() {
if (selectedCheckboxes.filter(":checked").length > 3){
$(this).removeAttr("checked");
alert("At most 3 tours may be compared.");
}
});
});
</script>
<sc:Placeholder ID="phHeader" Key="ph_header" runat="server" />
【问题讨论】:
-
我先添加“});”在脚本的末尾。
-
它正在关闭,我剪掉了一些正常运行的 j/s,然后 $(document).ready 被关闭了 - 我只是忘了把它包括在这里。
-
你试过在firefox中打开Firebug运行它吗?这将有助于调试问题。
-
是的——在朋友的帮助下,我们决定可能需要将“事件”作为参数传递——一旦我得出结论,如果这是解决方案,我会更新它。
-
你的朋友是对的。就目前而言,
event.preventDefault()不起作用,因为函数中没有名为event的变量(至少在我们所见的范围内)。
标签: javascript asp.net internet-explorer firefox google-chrome