2012-02-17 56 views
0
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <link rel="stylesheet" type="text/css" href="plugin/easyui/themes/gray/easyui.css"> 
    <link rel="stylesheet" type="text/css" href="plugin/easyui/themes/icon.css"> 
    <link rel="stylesheet" type="text/css" href="style/main.css"> 
    <script type="text/javascript" src="plugin/easyui/jquery-1.7.1.min.js"></script> 
<script type="text/javascript"> 
$("#closeMe").click(function() { 
    $(this) 
     .parent() 
     .slideUp(); 
}); 
</script> 
</head> 

<body> 
<div id="rem"> 
<span id="closeMe"><img src="http://www.cespage.com/silverlight/appbar/dark/close.png"></span> 
<p>Please read the documentation.For updates please follow our blog, tweets or become a fan.</p> 
</div> 
</body> 
</html> 

這是一個帶關閉按鈕的簡單框,一旦按下,它就會向上滑動。但是,當我測試它,我按下按鈕,沒有反應。問題是什麼?謝謝。爲什麼在這種情況下無法啓動腳本

+0

你使用的是什麼瀏覽器。某些版本的IE不會將點擊事件綁定到非A標籤。 – 2012-02-17 05:40:31

+0

從來沒有聽說過這個問題,j_mcnally。你確定?無論如何,真正的問題是文件還沒有準備好。 – 2012-02-17 05:42:40

+0

@j_mcnally - 這IE的版本會是這樣?它在5.5以後的所有版本中都適用於我(之前我不記得以前的版本),儘管我只使用了Windows版本...... – nnnnnn 2012-02-17 05:43:28

回答

1

你的初始化代碼應該是一個$(document).ready()調用內部,就像這樣:

<script type="text/javascript"> 
$(document).ready(function(){ 
    $("#closeMe").click(function() { 
     $(this) 
      .parent() 
      .slideUp(); 
    }); 
}); 
</script> 

至於是,它試圖運行#closeMe項目甚至存在了。 $(document).ready()確保它等到DOM準備就緒。

+0

這些當然是低懸的水果問題...打我5秒。 ;-) – 2012-02-17 05:41:06

+0

@GregPettit D'哦!我通常不會嘗試「快速繪製」的東西,但我想我會給這個鏡頭!呵呵 – 2012-02-17 05:42:20

0

包裹代碼就緒處理程序中

$(function(){  
$("#closeMe").click(function() { 
    $(this) 
     .parent() 
     .slideUp(); 
    });  
}); 

或可替換地在文檔的末尾移動腳本像

<body> 
<div id="rem"> 
<span id="closeMe"><img src="http://www.cespage.com/silverlight/appbar/dark/close.png"></span> 
<p>Please read the documentation.For updates please follow our blog, tweets or become a fan.</p> 
</div> 
</body> 
<script type="text/javascript"> 
$("#closeMe").click(function() { 
    $(this) 
     .parent() 
     .slideUp(); 
}); 
</script> 
0

你需要用你的jQuery的功能,所以它在頁面完成工作:

$(function() { 

    $("#closeMe").click(function() { 
     $(this).parent().slideUp(); 
    }); 

} 
相關問題