JavaScript增强AJAX基础
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript增强AJAX基础相关的知识,希望对你有一定的参考价值。
<title>js类型</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<script type="text/javascript">
//num为number类型
var num = 100;
//str为string类型,注意js中的string类型用‘‘或""均可
var str = "哈哈";
//flag为boolean类型
var flag = true;
</script>
<script type="text/javascript">
//多个script块中的内容,可以相互访问
//alert(flag);
var person = null;
var card;
//alert(card);
//undefined不是字符串,它是一种类型,如果你想判断某个变量是否为undefined,
//通过如下代码判断:
if(card == undefined){
alert("card变量暂没值");
}else{
alert(card);
}
</script>
<title>JS中有三种定义函数的方式</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<script type="text/javascript">
/*正常方式(先)
function add(num1,num2){
return num1 + num2;
}
window.alert("10+20=" + add(10,20));
*/
</script>
<script type="text/javascript">
/*构造器方式,最后一个参数为函数体,每个参数都是字符串类型(后)
var add = new Function("num1","num2","return num1+num2");
window.alert("100+200=" + add(100,200));
*/
</script>
<script type="text/javascript">
/*直接量或匿名或无名方式(再)
var add = function(num1,num2){
return num1 + num2;
}
window.alert("1000+2000=" + add(1000,2000));
*/
</script>
<title>JS中有四种对象</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<script type="text/javascript">
//Date
//var nowStr = new Date().toLocaleString();
//window.document.write(nowStr + "<br/>");
//Math
//for(var i=1;i<=10;i++){
// //1到9之间的随机整数
// document.write(Math.floor(Math.random()*9)+1 + "<br/>");
//}
//string
//var str = "Hello你好";
//var size = str.length;
//alert(size);//7
//Array
//var array = new Array("语文","数学","英语",true,123);
//for(var i=0;i<array.length;i++){
// document.write(array[i] + " ");
//}
</script>
<script type="text/javascript">
/*自定义对象
function Person(id,name,sal){
this.id = id;
this.name = name;
this.sal = sal;
}
var p = new Person(1,"波波",7000);
document.write("编号:" + p.id + "<br/>");
document.write("姓名:" + p.name + "<br/>");
document.write("薪水:" + p.sal + "<br/>");
*/
</script>
<script type="text/javascript">
//window对象,打开新窗口
//var url = "04_images.html";
//window.open(url);
</script>
<script type="text/javascript">
//status对象,将当前时间设置到状态栏中
//var nowStr = new Date().toLocaleString();
//window.status = nowStr;
</script>
<script type="text/javascript">
//location对象,模拟用户在地址栏输入url访问其它页面的情况
//var url = "04_images.html";
//window.location.href = url;
</script>
<script type="text/javascript">
//history对象,演示刷新
window.history.go(0);
</script>
<form action="04_images.html" method="POST">
<input type="button" value="提交"/>
</form>
<!-- 演示用JS提交表单,重要 -->
<script type="text/javascript">
//定位提交按钮
var inputElement = document.getElementsByTagName("input")[0];
//为提交按钮添加单击事件
inputElement.onclick = function(){
//定位<form>标签,forms表示document对象中所有表单的集合,通过下标引用不同的表单,从0开始
var formElement = document.forms[0];
//提交表单,提交到action属性指定的地方
formElement.submit();
}
</script>
以上是关于JavaScript增强AJAX基础的主要内容,如果未能解决你的问题,请参考以下文章