2014-01-27 60 views
0

所以我有這個jQuery腳本,但是當你點擊按鈕時,它並沒有按照它的設想去做。jQuery腳本不工作?

我在不同的按鈕上使用相同的腳本,它的工作原理。

似乎無法找到問題d:

jQuery腳本:

<script type="text/javascript"> 
$(document).ready(function(){ 
    $("#stop").click(function() { 
     var host = $("host").val(); 
     if(host != ""){ 
      $("#bootres").html("<p class='box'><img src='http://urgentbooter.com/img/ajax-loader.gif' border='0' alt='' /> Stopping attack...</p>"); 
      $.post("index.php?action=boot",{host:host,port:port,time:time,method:"STOP",submit:"submit2"},function(data){ 
     } else { 
      alert("The host field must contain the IP to the attack you want to stop!"); 
      $("#host").focus(); 
     } 
    }); 
}); 
</script> 

按鈕代碼:

<button type="button" id="stop" class="button red">Stop Attacks</button> 

順便說其他的按鈕,它適用於幾乎相同的代碼並在同一頁上。

讓我知道是否需要更多信息!

+0

我的單擊事件處理程序後和VAR主機前行擺正「警報(‘測試’);」當你點擊按鈕時它不起作用,如果有幫助的話。 – user3023566

+0

只是一個提示:嘗試查看您的控制檯中有哪些錯誤。它會告訴你很多關於這種錯誤的信息! felix的答案將解決我認爲的問題! –

+0

它顯示在第98行還有一個意外的標記,這是其他地方說的{alert(「主機字段」....等.. – user3023566

回答

3

你打開這個功能:

$.post("index.php?action=boot",{host:host,port:port,time:time,method:"STOP",submit:"submit2"},function(data){ 

這個函數是空的,以前else關鍵字

3

嘗試改變:

var host = $("host").val(); 

到:

var host = $("#host").val(); 

你忘了給#這裏瞄準id

+0

沒有幫助:/連警報不起作用 – user3023566

+0

@ user3023566你可以在這裏發佈相關的HTML標記嗎?目前你只顯示按鈕代碼 – Felix

+0

你想讓我做一個jsFiddle? – user3023566

1

問題是與你的代碼比對未關閉。

檢查你的if塊。

試試這個代碼:

$(document).ready(function(){ 
    $("#stop").click(function() { 
     var host = $("#host").val(); 
     if(host != ""){ 
      $("#bootres").html("<p class='box'><img src='http://urgentbooter.com/img/ajax-loader.gif' border='0' alt='' /> Stopping attack...</p>"); 
      $.post("index.php?action=boot",{host:host,port:port,time:time,method:"STOP",submit:"submit2"},function(data){ 
      });} 

        else { 
      alert("The host field must contain the IP to the attack you want to stop!"); 
      $("#host").focus(); 
     } 
    }); 
});