今天试了下jQuery上的几个小例子,刚开始时半天没摸到门,google之后才找到点感觉。
<html>
<head><title></title>
<script src="js/jquery-1.3.1.js" ></script>
<script language="javascript">
//文档加载完
$("document").ready(function(){
$(document.body).css( "background", "lightblue" );
//
$(document.body).click(function(){
$("div").each(function(i){
if(this.style.color!="blue"){
this.style.color = "blue";
}else{
this.style.color = "";
}
});
});
});
//追加内容
$(function(){
$("<div><p>Hello World!!</p></div>").appendTo("body");
});
//修改属性信息
$(function(){
$("a").attr("target","_blank");
$("a").attr("href","http://www.baidu.com");
$("a").click(function(){
alert("单击事件");
});
});
//捕捉文本框的内容改变事件
$(function(){
$("input[name='username']").change( function() {
// 这里可以写些验证代码
alert($(this).val());
alert($(this).attr("value"));
});
});
//为div加边框
$(function(){
$("div > p").css("border", "1px solid gray");
});
</script>
<style>
div { color:red; text-align:center; cursor:pointer;
font-weight:bolder; width:300px; }
</style>
</head>
<body>
<p>one</p> <div><p>two</p></div> <p>three</p>
<p><a href="#">test</a></p>
<p><input type="text" name="username" /></p>
</body>
</html>