Jquery 简单示例程序
0,基本用法 把.js 引用到项目中,代码如下
<script language="javascript" src="jquery-1.4.2.min.js"></script>
1,显示
<img style="display:none" src="20081027angsif.jpg" />
<input type="button" value="test" onclick=$('img').show(); />
如果想调用ID的显示,$('#img').show(); 即可。
2,简单的图片淡入淡出代码
<img id="mimg" style="display:none" src="20081027angsif.jpg" />
<script language="javascript">
var g=0;
function huan(){
if(g%2==0){
$('#mimg').fadeIn("slow",function (){ g++;
});
}
else {
$('#mimg').fadeOut("slow",function (){g++;
});
}
}
window.setInterval(huan,100);
</script>
3,ajax 请求
jquery ajax
<script language="javascript" src="js/jquery-1.4.2.min.js"></script>
<script>
function jajax(){
$.get("area_getAll.action","",function (data, textStatus){
document.getElementById("selectAdd").innerHTML=data;
},"text");
}
$(document).ready(jajax());
</script>
普通的写法:
function AjaxObject() {
this.req = null;
this.getHttpXMLRequest = function () {
if (window.XMLHttpRequest) {
this.req = new XMLHttpRequest();
} else {
if (window.ActiveXObject) {
this.req = new ActiveXObject("Microsoft.xmlhttp");
}
}
};
this.sendRequest = function (url, params, HttpMethod) {
if (!HttpMethod) {
HttpMethod = "POST";
}
this.getHttpXMLRequest();
if (this.req) {
this.req.onreadystatechange = this.showData;
this.req.open(HttpMethod, url, true);
this.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
this.req.send(params);
}
};
this.showData = function () {
};
}
function majax()
{
var ajax = new AjaxObject();
ajax.showData = function(){
if(ajax.req.readyState==4){
var str=ajax.req.responseText;
document.getElementById("msgdiv").innerHTML=str;
}
}
ajax.sendRequest("upwd.action","spwd="+document.forms['upwd'].spwd.value+"&npwd="+document.forms['upwd'].npwd.value);
}