jQuary 语法知识

jQuary语法实例

$(this).hide();

演示jQuary hide 函数,隐藏当前的HTML元素 ,代码如下:

<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>

$("#text").hide();
演示jQuery hide 函数,隐藏id="text"的标签元素,代码如下:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("#test").hide();
  });
});
</script>
</head>

<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p id="test">This is another paragraph.</p>
<button type="button">Click me</button>
</body>

</html>

jQuery 语法
jQuery语法是根据HTML元素编制的,可以对HTML元素进行操作

基础语法是:$(selector).acttion()

  • 美元符号定义 jQuery
  • 选择符(selector)“查询”和“查找” HTML 元素
  • jQuery 的 action() 执行对元素的操作

可参考上边代码

注意:所有jQuery函数都放在 document. ready函数中,这是为了防止文档在为加载完成前就运行jQuary函数代码

$(document).ready(function(){

 

posted @ 2015-05-18 09:13  zhenximeiyitian  阅读(161)  评论(0编辑  收藏  举报