Showing posts with label Basic. Show all posts
Showing posts with label Basic. Show all posts

Wednesday, October 01, 2008

jQuery Basic Selectors usage example


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" charset="utf-8" src="/lib/jquery/jquery-1.2.6.js"></script>
<style type="text/css" media="screen">
table td {
border: #ddd 1px solid;
}
div {
min-height: 20px;
border: #ddd 1px solid;
margin: 3px;
}
.colored {
background-color: #919;
}
</style>
</head>
<body>
<div id="myID.entry[0]">id="myID.entry[0]"</div>
<div id="myID.entry[1]">id="myID.entry[1]"</div>
<div id="myID.entry[2]">id="myID.entry[2]"</div>
<span>span</span>
<p>p</p>
<p>p</p>
<div>div</div>
<span>span</span>

<p>p</p>
<div>div</div>
<b></b>

<table>
<tr><td>Row with Index #0</td></tr>
<tr><td>Row with Index #1</td></tr>
<tr><td>Row with Index #2</td></tr>
<tr><td>Row with Index #3</td></tr>
<tr><td>Row with Index #4</td></tr>
<tr><td>Row with Index #5</td></tr>
<tr><td>Row with Index #6</td></tr>
<tr><td>Row with Index #7</td></tr>
<tr><td>Row with Index #8</td></tr>
<tr><td>Row with Index #9</td></tr>
</table>
<h1>Header 1</h1>
<p>Contents 1</p>
<h2>Header 2</h2>
<p>Contents 2</p>

<div>
<input type="checkbox" name="a" />
<span>Mary</span>
</div>

<div>
<input type="checkbox" name="b" />
<span>Paul</span>

</div>
<div>
<input type="checkbox" name="c"/>

<span>Peter</span>
</div>

<button id="run">Run</button>
<div></div>
<div id="mover"></div>
<div></div>

<script type="text/javascript" charset="utf-8">
// isSimple = /^.[^:#\[\.]*$/; // if id concludes such as ( :, #, [, ] ), you should backslashed these chararcters.
console.log($("#myID\\.entry\\[0\\]"));
$("#myID\\.entry\\[1\\]").css("border","3px solid red");


var list = $("div,p,span").map(function () {
return this.tagName;
}).get().join(", ");
$("b").append(document.createTextNode(list));

// function animateIt() {
// // console.log('endless loop');
// $("#mover").slideToggle("slow", animateIt);
// }
// animateIt();
//
// $("#run").click(function(){
// $("div:animated").toggleClass("colored");
// });

$("tr:even").css("background-color", "#bbf");
$("tr:odd").css("background-color", "#ffb");

// Matches all elements that are headers, like h1, h2, h3 and so on.
$(":header").css({ background:'#ccc', color:'blue' });

$("input:last")[0].checked = true;
$("input:not(:checked) + span").css("background-color", "yellow");
$("input").attr("disabled", "disabled");

$("td:lt(4)").css("color", "red");
$("td:gt(4)").css("color", "green");

</script>
</body>
</html>

Friday, March 23, 2007

PHP5 class basic

The Basics

class

Every class definition begins with the keyword class, followed by a class name, which can be any name that isn't a reserved word in PHP. Followed by a pair of curly braces, which contains the definition of the classes members and methods. A pseudo-variable, $this is available when a method is called from within an object context. $this is a reference to the calling object (usually the object to which the method belongs, but can be another object, if the method is called statically from the context of a secondary object). This is illustrated in the following examples:
Example 19-1. $this variable in object-oriented language


<?php
class A
{
function foo()
{
if (isset($this)) {
echo '$this is defined (';
echo get_class($this);
echo ")\n";
} else {
echo "\$this is not defined.\n";
}
}
}

class B
{
function bar()
{
A::foo();
}
}

$a = new A();
$a->foo();
A::foo();
$b = new B();
$b->bar();
B::bar();
?>
The above example will output:

$this is defined (a)
$this is not defined.
$this is defined (b)
$this is not defined.

Example 19-2. Simple Class definition

<?php
class SimpleClass
{
// member declaration
public $var = 'a default value';

// method declaration
public function displayVar() {
echo $this->var;
}
}
?>
The default value must be a constant expression, not (for example) a variable, a class member or a function call.
Example 19-3. Class members' default value

<?php
class SimpleClass
{
// invalid member declarations:
public $var1 = 'hello '.'world';
public $var2 = <<hello world
EOD;
public $var3 = 1+2;
public $var4 = self::myStaticMethod();
public $var5 = $myVar;

// valid member declarations:
public $var6 = myConstant;
public $var7 = self::classConstant;
public $var8 = array(true, false);


}
?>