好的...所以用户将信息输入到日志字段并点击提交,并且调用他们提交的信息函数,我称之为changeTextComment()。该函数调用另一个函数,依此类推,因为信息被格式化并放在提示中,就像在Facebook评论中一样。
我需要保存这些信息,以便以后可以在本地存储中调用,这样每次重新启动时都不会刷新应用程序。所以...
<script>
function appCache() {
// Check browser support
// this is experimental for local storage...
more here: http://www.w3schools.com/html/html5_webstorage.asp
if (typeof(Storage) != "undefined") {
localStorage.setItem(para);
// Retrieve
document.getElementById("journal").innerHTML = localStorage.getItem(para);
} else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support Web Storage...";
};
</script>
所以看看appCache函数似乎它可能会工作,除了我需要确定将存储然后检索的关键变量是什么。
我认为这是变量userInput,因为只要用户点击“添加到期刊”即可。 button此变量用于存储用户输入,然后放入changeTextComment()函数。
我想知道这是否是处理这一切的最简单方法......我还不了解数据库,但想知道这是否更容易学习。
在这种情况下,我会将函数Appcache()添加到函数changeText()中,以便它缓存变量,然后我将如何设置它然后将变量的缓存信息的值提供到在启动应用程序时更改textText()?
每次提交给期刊都会有独特的价值。
继续使用ChangeTextComment()函数......仍在整理如何在css中使用类来简化这些函数:
function changeTextComment(){
// to be modified from the above to change the location of the dump
var userInput = document.getElementById('userInput').value;
// get the input from the user
var panel = document.createElement("div"); // create a parent divider for everything
// assignment of attributes
panel.setAttribute("class","panel panel-default panel-body");
panel.setAttribute("id","panelBody");
var para = document.createElement("P");
var t = document.createTextNode(userInput);
para.appendChild(t);
// add comment area
var c = document.createElement("INPUT");
c.setAttribute("type", "text");
c.setAttribute("id", "comment");
c.setAttribute("placeholder", "comment here");
c.setAttribute("class", "form-control input-lg");
// add comment button attempt -- success <> now try to put it in the textarea
var d = document.createElement("INPUT");
d.setAttribute("type","button");
d.setAttribute("class","btn btn-info active pull-right");
d.setAttribute("onclick","commentThis()");
d.setAttribute("value","Add Comment");
panel.appendChild(para); // this is where a comments piece would go
// place the item
var destination = document.getElementById("journal")
//destination.insertBefore(Commentaryarea, destination.firstChild);
//destination.insertBefore(panel, destination.firstChild);
destination.insertBefore(panel, destination.firstChild);
panel.appendChild(c);
panel.appendChild(d);
document.getElementById("userInput").value = "";
document.getElementById("userInput").focus();}
</script>
<script>
function setText(a){
document.getElementById("userInput").value = a
document.getElementById("userInput").focus();
}
</script>
答案 0 :(得分:0)
当你说&#34;本地存储&#34;时,你的意思是存储在访问者浏览器中,即只有他们自己能够看到并检索它吗?或者您希望其他用户能够查看数据,和/或评论者是否能够在以后从其他位置登录时看到它?
如果它是后者,那么你需要将它存储在服务器端,并且你需要一个数据库。如果您只需要存储日记帐分录,那么使用javascript就可以轻松设置mongoDB,但如果您有很多关系(日记帐分录与用户关联,则条目评论与用户和条目相关联等)那么也许一个SQL数据库会更适合你。