我想将部分html代码保存为json作为文件,然后重新记录html代码进行编辑.知道我该怎么办?
我是json的新手,请尽可能简化.我看过其他问题,但他们似乎没有解决我的问题
你想要做的是称为序列化.
// This gives you an HTMLElement object var element = document.getElementById('TextBoxesGroup'); // This gives you a string representing that element and its content var html = element.outerHTML; // This gives you a JSON object that you can send with jQuery.ajax's `data` // option, you can rename the property to whatever you want. var data = { html: html }; // This gives you a string in JSON syntax of the object above that you can // send with XMLHttpRequest. var json = JSON.stringify(data);