jquery
来源:互联网 发布:c4dr16注册机mac 编辑:程序博客网 时间:2024/05/16 09:47
语法实例:
1.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>
2.<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>
3.
script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button type="button">Click me</button>
</body>
解释:
示例
$(this).hide() - 隐藏当前元素
$("p").hide() - 隐藏所有段落
$("p.test").hide() - 隐藏所有 class="test" 的段落
$("#test").hide() - 隐藏所有 id="test" 的元素
提示:jQuery 使用的语法是 XPath 与 CSS 选择器语法的组合。在本教程接下来的章节,您将学习到更多有关选择器的语法。
‘1.
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").hide(1000);
});
});
</script>
</head>
<body>
<button type="button">隐藏</button>
<p>这是一个段落。</p>
<p>这是另一个段落。</p>
</body>
2.
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").css("background-color","red");
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button type="button">Click me</button>
</body>
3
$(document).ready(function(){
$("#hide").click(function(){
$("p").hide();
});
$("#show").click(function(){
$("p").show();
});
});
</script>
</head>
<body>
<p id="p1">如果点击“隐藏”按钮,我就会消失。</p>
<button id="hide" type="button">隐藏</button>
<button id="show" type="button">显示</button>
</body>
获取到节点
<script language="javascript" >
$(function(){ // dom元素加载完毕
$("p").click(function(){//获取页面中的所有p元素 , 给每一个p元素添加onclick事件.
//doing something...
alert("suc!");
})
})
</script>
.addClass()
1.Description: Adds the specified class(es) to each of the set of matched elements.
$( "p" ).last().addClass( "selected" );
$( ".inner" ).after( "<p>Test</p>" );
$( "<div></div>" ).after( "<p></p>" );
3.Description: Insert content, specified by the parameter, to the end of each element in the set of matched elements.
- JQuery
- JQuery
- JQuery
- JQuery
- JQuery
- JQuery
- JQuery
- JQuery
- JQuery
- JQuery
- JQuery
- JQuery
- JQuery
- JQUERY
- jquery
- jQuery
- jquery
- jquery
- Java-子类同时继承抽象类和实现接口
- struts2原理
- java动态代理笔录
- POJ 2533 求最长上升子序列长度 非DP 实现
- 设计模式之命令模式
- jquery
- android 卸载SD卡后图库读取不到内部存储卡的图片
- bitmap与桶方式对1000万数据进行排序
- POJ 2299 树状数组求逆序数+离散化
- Thread1:Program received signal
- 代码备忘:常用SQL
- 内存静态分配和动态分配的区别
- informatica利用ant发送邮件
- Spring Ioc和Aop原理