jsoneditor/examples/01_basic_usage.html

51 lines
1.1 KiB
HTML
Raw Normal View History

2013-01-06 05:19:38 +08:00
<!DOCTYPE HTML>
<html>
<head>
<title>JSONEditor | Basic usage</title>
<link href="../dist/jsoneditor.css" rel="stylesheet" type="text/css">
<script src="../dist/jsoneditor.js"></script>
<style type="text/css">
#jsoneditor {
width: 500px;
height: 500px;
}
</style>
2013-01-06 05:19:38 +08:00
</head>
<body>
<p>
<button id="setJSON">Set JSON</button>
<button id="getJSON">Get JSON</button>
</p>
<div id="jsoneditor"></div>
2013-01-06 05:19:38 +08:00
<script>
// create the editor
var container = document.getElementById('jsoneditor');
2016-01-12 19:40:23 +08:00
var options = {};
var editor = new JSONEditor(container, options);
2013-01-06 05:19:38 +08:00
// set json
document.getElementById('setJSON').onclick = function () {
var json = {
'array': [1, 2, 3],
'boolean': true,
'color': '#82b92c',
'null': null,
'number': 123,
'object': {'a': 'b', 'c': 'd'},
'string': 'Hello World'
};
editor.set(json);
};
2013-01-06 05:19:38 +08:00
// get json
document.getElementById('getJSON').onclick = function () {
var json = editor.get();
alert(JSON.stringify(json, null, 2));
};
</script>
2013-01-06 05:19:38 +08:00
</body>
</html>