JavaScript中的正则表达式,用于测试URL中的文本

时间:2014-08-19 20:35:41

标签: javascript regex url

我从这里使用不同的工作代码得到了这个,但是我不明白为什么这不起作用以及如何使它工作......

基本上这应该使用一些regext表达式来测试页面" page1.aspx"和" page2.aspx" (案例可以是大写和小写)。如果它符合该标准,还应确保该网址不包含" text1"和" text2"。这就是我的......

<script> 

if (/page1\.aspx||page2\.aspx/i.test(self.location.href)) {
    if (!/text1||text2/i.test(self.location.href)) {
            var warnMessage = true;

            window.onbeforeunload = function (event) {
                if (!warnMessage) {
                    return;
            }
                else {
                    return "Please save first.";
                }
            }

            $(document).ready(function () {
                $('input:submit, .buttons').click(function () {
                    warnMessage = false;
                });
            });
    } 
} 

</script>

0 个答案:

没有答案