我创建了一个文件 upload.php
用户可以上传标题、文本、图像,并设置颜色、背景颜色。根据他们的愿望,。但是如何按原样提交这些数据。我为此使用了 jquery 和 javascript。例如
创建标题。(我没有写完整的脚本,但如果有人需要我可以更详细地解释)
$("#button1").click(function(){var heading = $("<h3></h3>").attr({contenteditable:"true"});
$("div").append(heading);});
如果用户想通过点击按钮2创建简单的文本
$("#button2").click(function(){var paragraph=$("<p></p>").attr({contenteditable:"true"});
$("div").append(paragraph);});
如果用户想先插入图片,他必须上传文件(长 php 脚本),然后通过以下方式插入图片
$("#button3").click(function(){var image= $("<img>")
.attr({src:"images/<?php echo $_FILES["img"]["name"];?>"});
$("div").append(image);});
并且用户也可以使用颜色来设置背景色
<input type="color" id="background"> <button type="button" onclick="setbackground()">
<script>
function setbackground(){document.getElementsByTagName("div").style.backgroundColor=document.getElementById("background").value;
但问题是当用户完成他想写的所有内容时,上传。现在他如何提交它,以便它可以按原样安全地上传到网站(即携带用户制作的所有效果)。
我尝试使用 <form>
和 php 但很难使用 <form>
实现所有的 css 效果我正在使用 <p></p>
不是<input>
.所以很难使用<form>
我很困扰 。它有点复杂,但请帮忙。我不是在询问整个脚本,只是一个提示会给我一些方向。
最佳答案
我会建议一个简单的解决方案。
您可以通过使用 .html()
保存用户的 html 来保存用户所做的所有编辑
例如:
var user_html = $("your main div").html();
你可以将它作为一个字符串来使用,以你想要的方式保存它,你也可以稍后重现它
例如:
$("your main div").html(user_html);
注意:请为您的 div 提供唯一 ID,并使用唯一 ID 进行附加。
关于javascript - 如何将数据按原样提交到另一个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39039013/