您的位置:首页 > Web前端 > JavaScript

JavaScript 基础语句

2009-11-28 00:02 246 查看
代码

document.write("<b>浏览器名称:</b>"+navigator.appName+"<br>");
document.write("<b>浏览器版本号:</b>"+navigator.appVersion+"<br>");
document.write("<b>运行平台:</b>"+navigator.platform+"<br>");
document.write("<b>是否支持cookie:</b>"+navigator.cookieEnabled+"<br>");

document.write("<b>高度:</b>"+screen.height+"<br>");
document.write("<b>宽度:</b>"+screen.width+"<br>");
document.write("<b>颜色深度:</b>"+screen.colorDepth+"<br>");

location.href="http://www.baidu.com"; 跳转

function look(a,b)
{
var result = a>b?a:b;
return result;
}
</script>

<script language="javascript">
function JieCheng(n)
{
if(n==1) {
return 1;
} else {
return n*JieCheng(n-1);
}
}
</script>

<script language="javascript">
if(confirm("您喜欢足球吗?")==true)
{
alert("喜欢!");
}
else
{
alert("不喜欢!");
}
</script>

<script language="javascript">
var age;
age = prompt("年龄:","22");
if(age==null){
alert("您的年龄保密");
}
else
{
alert("您的年龄为"+age);
}
</script>

//--------------事件

<script language="javascript">
function catchEvent()
{
var eventSrcID = event.srcElement.id;
var eventtype = event.type;
alert(eventSrcID+"捕获到了"+eventtype+"事件");
}
</script>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>mouse</title>
<script language="javascript">
function GetPosition()
{
var posX = event.clientX;
var posY = event.clientY;
window.status = "鼠标的位置是("+posX+","+posY+")";
}
</script>
</head>
<body onMouseMove="GetPosition();">
</body>
</html>

function GetKey()
{
textfield.value=event.keyCode+","+String.fromCharCode(event.keyCode);
}
</script>

------------XML (1)

var document_xml = new ActiveXObject("Microsoft.XMLDOM");
document_xml.load("info.xml");
var nameNode = document_xml.getElementsByTagName("name"); //获得文档中所有<name>标记

var str = nameNode(0).firstChild.nodeValue

------------XML(2)

var document_xml = new ActiveXObject("Microsoft.XMLDOM");
document_xml.load("info.xml"); //加载info.xml
var RootNode = document_xml.documentElement; //获得info.xml文档的根节点
var FirstNode = RootNode.firstChild; //获得根标记的第一个子节点
var SecondNode = RootNode.lastChild; //获得根标记的最后一个子节点
var nameNode = FirstNode.firstChild;
var ageNode = nameNode.nextSibling; //获得nameNode节点的下一个兄弟结点

------------更改元素document

document.images["saint"].src=imageArray[index];

document.write("第一个连接的信息:<br>");
document.write("<b>href:</b>"+document.links[0].href+"<br>");
document.write("<b>pathname:</b>"+document.links[0].pathname+"<br>");
document.write("<b>port:</b>"+document.links[0].port+"<br>");
document.write("<b>protocol:</b>"+document.links[0].protocol+"<br>");
document.write("<b>target:</b>"+document.links[0].target+"<br>");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: