如何让用户编辑网页内容并保存给所有观众? [英] How to allow users to edit content of webpage and save it for all viewers?

查看:168
本文介绍了如何让用户编辑网页内容并保存给所有观众?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个以简单文本开头的网站,你好。然后,任何访问该网站的人都可以将内容更改为任何他们喜欢的内容,而不仅仅是为了他们自己,而是为网站本身保存。然后另一个观众可以进来改变它,等等。我想保留所有编辑内容的数据库,但仅限于我自己。



所以我的问题是,什么工具/语言会对这个?或者任何人都可以指向任何教程?我是一个初学者,我不知道从哪里开始。这看起来真有帮助,但它似乎只为自己做出改变: http://www.developerdrive.com/2012/06/allowing-users-to-edit-text-content-with-html5/



很抱歉,如果这是一个非常简单的问题,我过于复杂。我很感激任何帮助!

解决方案

您的问题有很多方面。首先,您可能需要注册/登录系统。为此,您将需要前端(javascript / jQuery)和后端(PHP)编程。



如果您有登录系统,您应该了解PHP会话。

您需要读取/写入数据库。这将是后端(PHP)。许多教程目前仅涵盖较旧的mysql_命令;您必须学习mysqli_或PDO格式(因为较旧的样式仍然有效,但已弃用)。



您应该学习jQuery和javascript。 jQuery会非常有帮助,不要听那些说你必须先学习javascript的人 - 我没有,我现在正在填写我在设计了很多网站后错过的javascript。



有很多地方可以找到教程,但我可以推荐这些:


  1. PHPAcademy。 org - 曾经是免费的,但现在只是低价格

    注册和登录教程

    PHP和MySQL与PDO和mysqli_


  2. TheNewBoston.com - 试试这个:

    Project Lisa - 未完成的教程,但非常好

    PHP简介

    介绍jQuery







你说的那个例子是正确的保存当前用户的编辑(以及该用户的未来访问)。这些更改保存在用户的本地计算机上,而不是保存在服务器上。在服务器上存储编辑的最简单方法是将它们写入数据库,例如MySQL。






这是一个为什么你可能更喜欢用纯javascript来学习jQuery:

javascript方式:

  function saveEdits(){
//获取可编辑元素
var editElem = document.getElementById(edit);

//获取编辑的元素内容
var userVersion = editElem.innerHTML;

//将内容保存到本地存储
localStorage.userEdits = userVersion;

//向用户写一个确认
document.getElementById(update)。innerHTML =编辑保存!;

}

jQuery方式:

  function saveEdits(){
//获取编辑的元素内容
var userVersion = $(#编辑)VAR()。

//将内容保存到本地存储
localStorage.userEdits = userVersion;

//给用户写一个确认
$(#update)。val(编辑保存!);






很少输入 - 特别是在整个项目中 - 使用jQuery的方式。此外,jQuery为您处理所有跨浏览器问题。使用javascript,您必须自己为每个浏览器编码。对于大多数开发人员来说,jQuery更快更简单。


I am trying to make a website where it starts with simple text, "Hello". Then, anyone who comes to the website can change the content to whatever they like, saving it not just for themselves but for the website itself. Then another viewer can come in and change it, and so on. I'd like to also keep a database of all edited content, but only for myself.

So my question is, what tools/languages would be helpful to this? Or can anyone point to any tutorials? I am such a beginner, that I have no clue really where to start. This seems really helpful, but it seems to make changes only for yourself.: http://www.developerdrive.com/2012/06/allowing-users-to-edit-text-content-with-html5/

Sorry if this is a very simple question that I am overcomplicating. I appreciate any help!

解决方案

There are many aspects to your question. First, you may need a registration/login system. For that, you will need both front-end (javascript/jQuery) and back-end (PHP) programming.

If you have a login system, you should learn about PHP sessions.

You will need to read/write into a database. This would be back-end (PHP). Many tutorials currently cover only the older mysql_ commands; you must learn either mysqli_ or PDO format (as the older style still works but is deprecated).

You should learn jQuery and javascript. jQuery will be very helpful, and don't listen to those who say you must learn javascript first -- I didn't and I am now filling-in what I missed about javascript after having designed numerous sites.

There are many places to find tutorials, but I can recommend these:

  1. PHPAcademy.org - used to be free, but is now just low-priced
    Registration and Login tutorial
    PHP and MySQL with PDO and mysqli_

  2. TheNewBoston.com -- try this one:
    Project Lisa - Unfinished tutorial but very good
    Intro to PHP
    Intro to jQuery


You are correct that the example you posted only saves edits for the current user (and for future visits by that same user). The changes are saved on the user's local computer, not on the server. The easiest way to store edits on the server is to write them to a database, such as MySQL.


Here is an example of why you might prefer to learn jQuery over plain javascript:

The javascript way:

function saveEdits() {
    //get the editable element
    var editElem = document.getElementById("edit");

    //get the edited element content
    var userVersion = editElem.innerHTML;

    //save the content to local storage
    localStorage.userEdits = userVersion;

    //write a confirmation to the user
    document.getElementById("update").innerHTML="Edits saved!";

}

The jQuery way:

function saveEdits() {
    //get the edited element content
    var userVersion = $("#edit").var();

    //save the content to local storage
    localStorage.userEdits = userVersion;

    //write a confirmation to the user
    $("#update").val("Edits saved!");

}

Much less typing -- especially over an entire project -- using the jQuery way. Also, jQuery takes care of all cross-browser issues for you. With javascript you must code for each browser yourself. For most developers, jQuery is faster and easier.

这篇关于如何让用户编辑网页内容并保存给所有观众?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆