初学 JQuery,经典的hello world!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>初学JQuery</title>
<script language="javascript" src="jquery-1.8.2.js" type="text/javascript"></script>
</head>
<body>
<div>一、引入"jquery-1.8.2.js"文件,进入JQuery的初体验吧!如下:<br/>
<input id="helloWorld1" type="button" value="点击我呀,隐藏"/>
<input id="helloWorld2" type="button" value="点击我呀,显示"/>
<input id="helloWorld3" type="button" value="点击我呀,显示或隐藏"/>
<p style="background-color:#CCC">点击按钮显示或隐藏此。 hello world!</p>
</div>
</body>
<script language="javascript">
$(document).ready(function(){//它的缩写方法:$(function(){ //do something });
$("#helloWorld1").click(function(){
$("p").hide();
});
$("#helloWorld2").click(function(){
$("p").show();
});
$("#helloWorld3").click(function(){
$("p").toggle();
});
});
</script>
</html>
分享到:
相关推荐
例如,`$("div").append("<p>Hello World</p>")`会在每个`<div>`元素内部追加一个`<p>`标签。 ### 3. 事件处理 jQuery的事件处理方式非常直观,`click()`, `mouseover()`, `mouseout()`等方法让事件绑定变得轻松。...
alert("Hello World!"); }); ``` #### 二、jQuery对象与DOM对象 **1. jQuery对象** - **定义** jQuery对象是指通过jQuery包装DOM对象后产生的对象。它是jQuery特有的对象类型。 - **使用** 如果一个...
例如:`$("<div><p>Hello World</p></div>").appendTo("body")`,这将在页面的`<body>`标签内创建并添加一个新的`<div>`元素及其内容。 - `$(elements)`:将一个或多个DOM元素转换成JQuery对象。例如:`$(document....
1. **内容创建**:Hexo支持Markdown、Textile等多种文本格式,用户只需在指定的 `_posts` 目录下创建文章,按照约定的文件命名规则(如:`2022-01-01-hello-world.md`),并编写文章内容。 2. **配置**:Hexo的配置...
message: 'Hello from the API world!' }) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error(error)); ``` 4. **错误处理**:在调用API时,可能会...