JQuery Notes

<script type="text/javascript" src="script.js"></script>

$(document).ready(something); says: "when the HTML document is ready, do something!"

$(document).ready(function() {
    var $target = $(‘li:nth-child(4)‘);
    $target.fadeOut(‘fast‘);
});

As you probably guessed, jQuery includes a .toggleClass() function that does exactly this. If the element it‘s called on has the class it receives as an input, .toggleClass() removes that class; if the target element doesn‘t have that class, .toggleClass() adds it.

$(document).ready(function(){
    $(‘#text‘).click(function(){
        $(‘#text‘).toggleClass(‘highlighted‘);
    });
});

.html() can be used to set the contents of the first element match it finds. For instance,

$(‘div‘).html();

will get the HTML contents of the first div it finds, and

$(‘div‘).html("I love jQuery!");

will set the contents of the first div it finds to "I love jQuery!"

.val() is used to get the value of form elements. For example,

$(‘input:checkbox:checked‘).val();

would get the value of the first checked checkbox that jQuery finds.

The .slideToggle() method animates the height of the matched elements. This causes lower parts of the page to slide up or down, appearing to reveal or conceal the items. If the element is initially displayed, it will be hidden; if hidden, it will be shown.

GChat List
index.html

<!DOCTYPE html>
<html>
    <head>
     <title>To Do</title>
        <link rel="stylesheet" type="text/css" href="stylesheet.css"/>
        <script type="text/javascript" src="script.js"></script>
 </head>
 <body>
  <h2>To Do</h2>
  <form name="checkListForm">
   <input type="text" name="checkListItem"/>
  </form>
  <div id="button">Add!</div>
  <br/>
  <div class="list"></div>
 </body>
</html>

stylesheet.css

h2 {
    font-family:arial;
}
form {
    display: inline-block;
}
#button{
    display: inline-block;
    height:20px;
    width:70px;
    background-color:#cc0000;
    font-family:arial;
    font-weight:bold;
    color:#ffffff;
    border-radius: 5px;
    text-align:center;
    margin-top:2px;
}
.list {
 font-family:garamond;
 color:#cc0000;
}

script.js

$(document).ready(function(){
    $(‘#button‘).click(function(){
        var toAdd = $(‘input[name=checkListItem]‘).val();
        $(‘.list‘).append(‘<div class="item">‘ + toAdd + ‘</div>‘);
    });
    $(document).on(‘click‘, ‘.item‘, function(){
        $(this).remove();
    });
});

Move the sprite

index.html

<!DOCTYPE html>
<html>
    <head>
     <title>Super Mario!</title>
        <link rel=‘stylesheet‘ type=‘text/css‘ href=‘stylesheet.css‘/>
  <script type=‘text/javascript‘ src=‘script.js‘></script>
 </head>
 <body>
        <img src="http://i1061.photobucket.com/albums/t480/ericqweinstein/mario.jpg"/>
 </body>
</html>

stylesheet.css

img {
    position: relative;
    left: 0;
    top: 0;
}

script.js

$(document).ready(function() {
    $(document).keydown(function(key) {
        switch(parseInt(key.which,10)) {
   // Left arrow key pressed
   case 37:
    $(‘img‘).animate({left: "-=10px"}, ‘fast‘);
    break;
   // Up Arrow Pressed
   case 38:
    $(‘img‘).animate({top: "-=10px"}, ‘fast‘);
    break;
   // Right Arrow Pressed
   case 39:
    $(‘img‘).animate({left: "+=10px"}, ‘fast‘);
    break;
   // Down Array Pressed
   case 40:
    $(‘img‘).animate({top: "+=10px"}, ‘fast‘);
    break;
  }
 });
});

.effect() ->argument ‘explode‘ ‘bounce‘ ‘slide‘
http://jqueryui.com/

Special Effects
index.html

<!DOCTYPE html>
<html>
    <head>
     <title>Behold!</title>
        <link rel=‘stylesheet‘ type=‘text/css‘ href=‘http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css‘/>
        <script type=‘text/javascript‘ src=‘script.js‘></script>
        <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
 </head>
 <body>
        <div id="menu">
            <h3>jQuery</h3>
            <div>
                <p>jQuery is a JavaScript library that makes your websites look absolutely stunning.</p>
            </div>
            <h3>jQuery UI</h3>
            <div>
                <p>jQuery UI includes even more jQuery goodness!</p>
            </div>
            <h3>JavaScript</h3>
            <div>
                <p>JavaScript is a programming language used in web browsers, and it‘s what powers jQuery and jQuery UI. You can learn about JavaScript in the <a href="http://www.codecademy.com/tracks/javascript" target="blank" style="text-decoration:none; color:#F39814">JavaScript track</a> here on Codecademy.</p>
            </div>
        </div>
 </body>
</html>

script.js

$(document).ready(function() {
    $("#menu").accordion({collapsible: true, active: false});
});

JQuery Notes,布布扣,bubuko.com

时间: 2024-08-27 08:43:14

JQuery Notes的相关文章

url编码 - JS &amp; jQuery Notes

Url传递特殊符号 十六进制值: 1. + URL 中+号表示空格 %2B 2. 空格 URL中的空格可以用+号或者编码 %20 3. / 分隔目录和子目录 %2F 4. ? 分隔实际的 URL 和参数 %3F 5. % 指定特殊字符 %25 6. # 表示书签 %23 7. & URL 中指定的参数间的分隔符 %26 8. = URL 中指定参数的值 %3D java对文字进行编码/解码涉及3对函数: escape/unescape: 采用ISO Latin字符集对指定的字符串进行编码.所有的

Jquery and Javascript Notes

工作就是一个学习的过程. 在这个过程中,你可以学到新的知识,你也可以温习你已经拥有的知识.JQuery Notes 是一个工作笔记.希望能帮助自己提升技术.会有更新..... 1.JQuery attr() Method The attr() method sets or returns attributes and values of the selected elements.           Return the value of an attribute;   $(selector)

JQuery Study Notes— A small demo for Smooth Animated Menu

1. Before expanding: 2.  coding: <!DOCTYPE html> <html> <head> <title>Smooth Animated Menu</title> <script src="http://jqueryjs.googlecode.com/files/jquery-1.3.js" type="text/javascript"></script&

JQuery Study Notes— A small demo for unfolding its content

1. Before unfolding: 2. After unfolding: 3. coding: <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Home</title> <style> .parent { width: 500px; color: white; } .l

jquery实现幻灯片

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>gakki</title> <style type="text/css"> *{ margin: 0; padding: 0; } html, body{ position: relative; width: 100%; height: 100%; } #wrap{

jQuery属性-attr()方法

定义和用法 attr() 方法设置或返回被选元素的属性值.根据选择 attr()方法 不同的参数,工作方式也会有点差异. 返回属性值-返回被选元素的属性值. 语法 $(selector).attr(attribute) 参数 描述 selector 被选元素 attribute 规定要获取被选元素(selector)的属性 例 <!DOCTYPE html> <html lang="en"> <head> <meta charset="

jQuery实现手机竖直手风琴效果

效果:http://hovertree.com/texiao/jquery/65/ 效果图: 代码: <!doctype html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta

Wordpress 音频播放器 Wordpress audio player with jQuery audioplayer.swf

原文地址:http://justcoding.iteye.com/blog/545978 Wordpress audio player with jQuery How to use Wordpress audio player (standalone version) with jQuery and jQuery SWFObject (progressive enhancement). <!-- SECTION "Wordpress audio player with jQuery&quo

基于jQuery 常用WEB控件收集

Horizontal accordion: jQuery 基于jQuery开发,非常简单的水平方向折叠控件. Horizontal accordion: jQuery jQuery-Horizontal Accordion 具有XBOX360 blade界面风格的水平方向Accordion. jQuery-Horizontal Accordion AutoComplete-JQuery jQuery插件易于集成到现在的表单中(Form). AutoComplete-JQuery Facebook