对不起,我无法详细说明我的问题,但我真的不能看到任何问题。这两个功能save()
和的onclick本地存储不能正常工作?不知道为什么
<button onclick="save()">save</button>
<button onclick="load()">load</button>
中的代码意味着load()
跑抢的所有输入的值,并save
它的本地存储。然后在load
添加保存的数据回到表格域
我是新来的PHP和JavaScript,所以它可能看起来有点凌乱,但那是因为我通过PHP数组和循环(“数组”更改根据与选项被选择时)
//保存
function save() {
if (typeof(Storage) != "undefined") {
var seometatitle = document.getElementById("seo_meta_title").value;
saveData(seometatitle);
function saveData(xseometatitle) {
localStorage.setItem("seometatitle", xseometatitle);
}
}
var seometadescription = document.getElementById("seo_meta_description").value;
saveData(seometadescription);
function saveData(xseometadescription) {
localStorage.setItem("seometadescription", xseometadescription);
}
}
var header = document.getElementById("header").value;
saveData(header);
function saveData(xheader) {
localStorage.setItem("header", xheader);
}
}
var pagetext = document.getElementById("page_text").value;
saveData(pagetext);
function saveData(xpagetext) {
localStorage.setItem("pagetext", xpagetext);
}
}
var linkurl = document.getElementById("link_url").value;
saveData(linkurl);
function saveData(xlinkurl) {
localStorage.setItem("linkurl", xlinkurl);
}
}
var buttontext = document.getElementById("button_text").value;
saveData(buttontext);
function saveData(xbuttontext) {
localStorage.setItem("buttontext", xbuttontext);
}
}
}} //end
// LOAD
function load() {
if (typeof(Storage) != "undefined") {
document.getElementById("seo_meta_title").value = localStorage.getItem("seometatitle");
document.getElementById("seo_meta_description").value = localStorage.getItem("seometadescription");
document.getElementById("header").value = localStorage.getItem("header");
document.getElementById("page_text").value = localStorage.getItem("pagetext");
document.getElementById("link_url").value = localStorage.getItem("linkurl");
document.getElementById("button_text").value = localStorage.getItem("buttontext");
}}
只是为了它的缘故这里是根儿的PHP吃了save function
$arrlength = count($matches[0]); # Get how many items in array two.
for($x = 0; $x < $arrlength; $x++) { #counting
$place_name = str_replace ("_" , "" , $matches[0][$x]); #Create readible name _ to space.
echo 'var ' .$place_name. ' = document.getElementById('.'"'.$matches[0][$x].'"'.').value;';
echo "\n";
echo 'saveData('.$place_name.');';
echo "\n";
echo 'function saveData(x'.$place_name.') {';
echo "\n";
echo 'localStorage.setItem("'.$place_name.'", x'.$place_name.');';
echo "\n";
echo '}}';
echo "\n";
这里是它的使用是针对load function
$arrlength = count($matches[0]); # Get how many items in array two.
for($x = 0; $x < $arrlength; $x++) { #counting
$place_name = str_replace ("_" , "" , $matches[0][$x]); #Create readible name _ to space.
// Retrieve
echo 'document.getElementById("'.$matches[0][$x].'").value = localStorage.getItem("'.$place_name.'");';
echo "\n"; }
数组的PHP,它由占位变化取决于HTML抓住{placeholder}
形式的.html文件自动进行使用的文件
array(1) {
[0]=> array(6) {
[0]=> string(12) "placeholders"
[1]=> string(15) "page_meta_title"
[2]=> string(6) "header"
[3]=> string(9) "page_text"
[4]=> string(8) "link_url"
[5]=> string(11) "button_text" }
}
}
任何帮助将不胜感激!谢谢你的时间。
请正确缩进您的代码以使其可读。 – jfriend00 2014-12-03 05:06:31