javascript加载xml文件
<mce:script language="javascript" type="text/javascript"><!--
//需要读取的xml文件
var uRl = "jsReadXml.xml";
var xmlDoc;
//初始化,给上述定义变量赋值
// function showcurcity(){
if(window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false"
xmlDoc.load(uRl);
getvalue();
}
else if(document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("", "root", null);
xmlDoc.load(uRl);
xmlDoc.onload=getvalueff;
}
// else {
// return null;
// }
// }
function getvalue()
{
var nodes=xmlDoc.documentElement.childNodes;
var now=new Date();
for(i=0;i<nodes.length;i++){
var value=nodes.item(i).childNodes.item(0).text ;
alert(nodes.item(i).childNodes.item(1).text);
alert(nodes.item(i).childNodes.item(2).text);
}
}
function getvalueff(){
var cCode=xmlDoc.getElementsByTagName("date");
var now = new Date();
var nowvalue=now.getFullYear()+'年'+(now.getMonth()+1)+'月'+now.getDate()+'日';
for(i=0;i<cCode.length;i++)
{
alert(xmlDoc.getElementsByTagName("imgsrc")[i].childNodes[0].nodeValue);
alert(xmlDoc.getElementsByTagName("title")[i].childNodes[0].nodeValue);
alert(xmlDoc.getElementsByTagName("url")[i].childNodes[0].nodeValue);
}
}
// --></mce:script>
相关文档:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>test</title>
<mce:style type="text/css"><!--
.table_back{width:480px;height:480px;border-bottom:1px solid bla ......
java代码
package com.xml.action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class XMLAction extends ActionSupport{
private static final long serialVersionUID = 1L;
private String username;
private String mobile;
public void setUs ......
用arguments对象检测传递给函数的参数个数:arguments.length
function test(){
if(arguments.length == 1)
alert(arguments[0] + ",你好");
else if(arguments.length == 2)
alert(a ......
document 文挡对象 - JavaScript脚本语言描述
---------------------------------------------------------------------
注:页面上元素name属性和JavaScript引用的名称必须一致包括大小写
否则会提示你一个错误信息 "引用的元素为空或者不是对象"
------------------------------------------- ......