/***************json****************/
var strjson = "[";
for(var i=0;i<abbrs.length;i++)
{
var abbr = abbrs[i];
var title = abbr.getAttribute("title");
alert("nodeValue:"+abbr.firstChild.nodeValue+" "+"nodeName:"+abbr.firstChild.nodeName+"nodeType:"+abbr.firstChild.nodeType);
var text = abbr.firstChild.nodeValue;
strjson += "{title:'"+ title +"',text:'"+ text +"'},";
}
strjson = strjson.substring(0,strjson.length-1);
strjson += "]";
var obj = eval("("+ strjson +")");
/****************json***************/
前台格式保存JSON格式
function preparePlaceholder() {
var placeholder = document.createElement("img"); //创建一个对象
placeholder.setAttribute("id","placeholder");//添加属性
placeholder.setAttribute("src","images/placeholder.gif");
placeholder.setAttribute("alt","my image gallery");
var desc = document.createElement("p");
desc.setAttribute("id","desc");
var desc_text = document.createTextNode("Choose an image");//Text
desc.appendChild(desc_text);//text添加到desc里<div id=desc>Choose an image</div>
var gallery = document.getElementById("imagegallery");
insertAfter(desc,gallery);
insertAfter(placeholder,desc);
}
//elements 不包括 label
//input textarea fieldset
//elements表单中所有控件的集合。input type=image 对象不在此集合内
function resetFields(whichform) {
for(var i=0;i<whichform.elements.length;i++){
var ele = whichform.elements[i];
if(ele.type == "submit") continue;
if(!ele.defaultValue) continue;
ele.onfocus = function(){
if(this.value == this.defaultValue){
this.value = "";}
}
ele.onblur = function(){
if(this.value == ""){
this.value = this.defaultValue;}
}
}
}
function prepareInternalnav() {
var nav = document.getElementById("internalnav");
links = nav.getElementsByTagName("a");
for (var i=0; i<links.length; i++ ){
var sid = links[i].getAttribute("href").split("#")[1];
if (!document.getElementById(sid)) continue;
document.getElementById(sid).style.display = "none";
links[i].id = sid;//分别赋值 links[i].XX 可以随便定义
links[i].onclick = function(){
showSection(this.id); //事件里当前对象(links[i])用 this
return false;
}
}
}