2012-02-17 15 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の一部のバージョンでは、クリックイベントを非タグにバインドしません。 –

+0

前にその問題について聞いたことはありません、j_mcnally。本気ですか?いずれにせよ、実際の問題は文書が準備ができていないということです。 –

+0

@j_mcnally - IEのどのバージョンですか?私はWindows版のみを使用していましたが、5.5以降のすべてのバージョンで私のために働いていました(その前のバージョンは覚えていません)... – nnnnnn

答えて

1

あなたのinitコードは次のように、$(document).ready()コール内にある必要があります:

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

ようになり、#closeMeアイテムも存在する前に実行しようとしています。 $(document).ready()は、DOMが準備完了するまで待機するようにします。

+0

これらの低懸念の果実の質問... 5秒で私を打つ。 ;-) –

+0

@GregPettit D'oh!私は通常 "クイックドロー"のものを試していないが、私はこれを撃つだろうと思った!ヘーヘ –

0

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

または代わりにあなたはそれがページの完了時に働くように、あなたのjqueryの機能をラップする必要が

<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

のようなあなたの文書の最後にスクリプトを移動する準備ができてハンドラ内のコードをラップ:

$(function() { 

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

} 
関連する問題