基本.click功能我无法开始工作jQuery

noW*_*ome 0 jquery

有谁知道我可能做错了什么?为什么这个基本的点击功能没有被执行到发送警报的程度.我有jQuery-1.7.1.js链接到我的页面.

jQuery的

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>


<script type="text/javascript" src="../fruith/jquery-1.7.1.js"></script>

<script type="text/javascript">
function checkedDark () {

$('#activate_post_checkbox').click(function(){
    alert('duh')

  $('#work').css('color', this.checked ? '#000' : '#666');

});


}
</script>

</head>
Run Code Online (Sandbox Code Playgroud)

HTML

<body>
<div id="work">blah blah blah</div>


<input type="checkbox" id="activate_post_checkbox" value="active"  /><span id="activate_post_checkbox_text">Make my posting active immediately.</span>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

sco*_*ttm 6

您需要在document.ready函数中分配click事件,或者先调用您的checkedDark()函数.

例如:

<script type="text/javascript">
$(function() { 

  $('#activate_post_checkbox').click(function(){
      alert('duh');
      $('#work').css('color', this.checked ? '#000' : '#666');
  });
});
</script>
Run Code Online (Sandbox Code Playgroud)