jquery教程 $("p").hide()

 

 

 


<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(

function(){
  $("button").click(
function(){
  $(this).hide();
}
);

  $("a").click(
function(){
  $(this).hide();
}
);

  $("span").click(
function(){
  $(this).hide();
}
);
}

);
</script>
</head>

<body>
<button type="button">Click me</button>

<a>dddd</a>

<span>spanhide</span>

</body>

</html>


jquery教程 $("p").hide()

 命令用tab缩进书写,可以更清晰的看到代码的层次结构,更易理解。

 

下面这个是上述代码的简化版,上面的代码是从下面扩充加了几行得到的:


<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(

function(){
  $("button").click(

function(){
  $(this).hide();
}

);
}

);
</script>
</head>

<body>
<button type="button">Click me</button>
</body>

</html>

<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
  $(this).hide();
});
});
</script>

注意在什么情况下,尾部要加分号;

function ( )不需要分号

 


$(document).ready(

);

 

 

$("button").click(

 

);

 

 

function(){


}