簡體   English   中英

此JQuery代碼有什么問題?

[英]What is wrong with this JQuery code?

<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>

它不會發出警報,但是為什么呢? 這是較早的工作,我忘記保存了。 它應該用另一個URL加上字段的值來代替url。 編輯:頭,html等標簽在那里。

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

您無需在任何地方聲明pathname ,這是:

if (pathname.indexOf("google")>= 0){

應該會導致控制台錯誤。

我想你想要的是location.pathname而不是pathname

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM