利用js將 json對象在textarea中賦值與展示

來源:互聯網
上載者:User

標籤:

明明很簡單的東西,可惜網上一大堆廢話。在此記錄,轉需。

 jsonStr = JSON.stringify(jsondata,null,4);

 

example:

<!doctype html><!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ --><!--[if lt IE 7 ]><html class="no-js ie6" lang="en"> <![endif]--><!--[if IE 7 ]><html class="no-js ie7" lang="en"> <![endif]--><!--[if IE 8 ]><html class="no-js ie8" lang="en"> <![endif]--><!--[if (gte IE 9)|!(IE)]><!--><html class="no-js" lang="en"> <!--<![endif]--><head>    <meta charset="utf-8">    <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame         Remove this if you use the .htaccess -->    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">    <title>flow CURD測試</title>    <!-- Mobile viewport optimized: j.mp/bplateviewport -->    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <!-- CSS: implied media="all" -->    <load href="/api/Application/Habo_v2/View/Index/style.css"/>    <load href="__PUBLIC__/css/bootstrap.min.css" />    <load href="__PUBLIC__/js/jquery.js" />    <load href="__PUBLIC__/js/bootstrap.min.js" />    <!-- All JavaScript at the bottom, except for Modernizr which enables HTML5 elements & feature detects --></head><body class="home"><div class="container">    <header>        <h3>flow CURD 介面測試</h3>    </header>    <form>        <div class="form-group">            <label for="flowid">FlowId:</label>            <input id="flowid" type="text" class="form-control" placeholder="input flowid here">        </div>        <div class="form-group">            <label for="flowdata">Example jsondata</label>            <textarea id="flowdata" class="form-control bg-muted code" rows="18" placeholder="Input flow json data here"></textarea>        </div>        <div class="form-group row">            <button id="createflow" type="button" class="btn btn-primary col-md-2 col-md-offset-2">建立</button>            <button id="updateflow" type="button" class="btn btn-primary col-md-2">修改</button>            <button id="searchflow" type="button" class="btn btn-primary col-md-2">尋找</button>            <button id="deleteflow" type="button" class="btn btn-primary col-md-2">刪除</button>        </div>    </form>    <div class="clear"></div></div><footer>    <div id="footer">        Copyright &copy;        <script type="text/javascript">            d = new Date();            document.write(d.getFullYear());        </script>        <span>Habo, Inc. All rights reserved.</span><br/>        Generated by <a href="http://Habo.oa.com">Habo</a>.    </div></footer></div> <!--! end of #container --><script>    $(function(){        $("#searchflow").click(function(){            var flow_id = $("#flowid").val();            var param = {                ‘flow_id‘ : flow_id            };            console.log("flowID",flow_id);            $.getJSON("/api/index.php/Habo_v2/DiyApi/getFlowData",data=param, function(jsondata){                jsonStr = JSON.stringify(jsondata,null,4);                $("#flowdata").val(jsonStr);                console.log("flowData: ",jsondata);            });        });    })</script></body></html>

 

利用js將 json對象在textarea中賦值與展示

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.