这个JQuery代码有什么问题?

这个JQuery代码有什么问题?,jquery,Jquery,它不警觉,但为什么?这是工作较早,我忘了保存它。它应该用另一个url加上字段中的值来替换url。编辑:头,html等。标签在那里 <script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <script type="text/javascript"> //

它不警觉,但为什么?这是工作较早,我忘了保存它。它应该用另一个url加上字段中的值来替换url。编辑:头,html等。标签在那里

<script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">                                         

//waits till the document is ready
$(document).ready(function() {
    //onclick function
    $('button.butter').click(function(){
        //code will only run on certain url
        if (pathname.indexOf("google")>= 0){
            alert('This doesn't work anymore!');  

           //replacer
          $("a[href*='https://google.com']").attr('href',('http://www.google.com/search?q' + $('#FormID').val()));
        }
        else{
            alert('Wrong page');
        }
    });
});

</script>
您不在任何地方声明路径名,这:

<button class="butter">Press</button>

应导致控制台中出现错误。

我认为您需要location.pathname而不是pathname

作为第一个警报,您需要跳出“in不起作用,对吗?检查web控制台并添加警报“This dosen't work”(此不再起作用);而不是你所拥有的
if (pathname.indexOf("google")>= 0){