简体   繁体   English

获取DIV的内容并保存到文件,jQuery / JS或服务器端

[英]Get the content of a DIV and save to a file, jQuery/JS or Server-side

In my site I need to get content of one of DIV and save the content to a file. 在我的网站中,我需要获取其中一个DIV的内容并将内容保存到文件中。

I'm just wondering whether is there possibility to to do it in jQuery or JS if not do I have to use server based language like PHP. 我只是想知道是否有可能在jQuery或JS中执行它,如果不是我必须使用像PHP这样的基于服务器的语言。

Or any one got example or tutorial relative this query? 或者任何人得到了这个查询的例子或教程?

Using jQuery, access the content of the div using .text(); 使用jQuery,使用.text();访问div的内容;

Then use jquery ajax function to POST this to a PHP script. 然后使用jquery ajax函数将此POST发送到PHP脚本。 Inside the php script you should open a file stream using fopen() with "w+" permission and then use fwrite() to write the contents into the file. 在php脚本中你应该使用带有“w +”权限的fopen()打开文件流,然后使用fwrite()将内容写入文件。

You can use jQuery's AJAX function to send the information to a script on the server that would create and save the file on the server. 您可以使用jQuery的AJAX函数将信息发送到服务器上的脚本,该脚本将在服务器上创建并保存文件。

Directly you cant use jQuery or JS to this purpose. 直接你不能使用jQuery或JS来达到这个目的。

You could also use the HTML5 Filesystem API to save the file in the browser and use a[download] to present the user with a download link. 您还可以使用HTML5 Filesystem API将文件保存在浏览器中,并使用a[download]向用户显示下载链接。 Alternatively, you could skip the Filesystem and just do the latter. 或者,您可以跳过文件系统,然后执行后者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM