此代码适用于chrome但不适用于Firefox和IE或Safari,我该如何解决?

时间:2014-10-31 14:54:53

标签: javascript jquery google-chrome internet-explorer firefox

我有这个代码......它在Google Chrome上工作正常,但是Firefox和EI以及Safari一直在反复播放警报。我应该添加什么来确保警报只进行一次。

<html>
    <script language="JavaScript">
        <!--

        document.onclick = myClickHandler;


        function myClickHandler() {
            alert("All orders require minimum two weeks notice before your event");
        }
        -->

        $(function() {
            $(document).on('click.once', function() {
                alert("Thank you for your visit. Happy shopping!!");
                $(document).off('click.once');
            })
        });
    </script>

</html>

1 个答案:

答案 0 :(得分:1)

 $(function() {
        $(document).on('click', function() {
            alert("Thank you for your visit. Happy shopping!!");
            $(document).unbind('click');
        })
  });