發(fā)文章
發(fā)文工具
撰寫
網(wǎng)文摘手
文檔
視頻
思維導(dǎo)圖
隨筆
相冊
原創(chuàng)同步助手
其他工具
圖片轉(zhuǎn)文字
文件清理
AI助手
留言交流
功能說明:
在左側(cè)輸入框中輸入Json串,,點(diǎn)擊執(zhí)行時根據(jù)輸入的Json串在右側(cè)展示區(qū)顯示出相應(yīng)的Html(使用Jquery1.4.4)
HTML:
<table style="width:100%; "> <col width="200px;" /> <tr> <td>Json輸入框</td> <td>展示區(qū)</td> </tr> <tr> <td> <textarea id="txtJson" rows="20" cols="50"> </textarea> </td> <td valign="top"> <div id="divShow"> </div> </td> </tr> <tr> <td></td> <td> <input id="btnExec" type="button" value="執(zhí)行" /> </td> </tr> </table>
JS代碼:
$(document).ready(function () { $("#btnExec").click(function () { try{ var objList = eval($("#txtJson").val()); jsonToControl(objList); } catch(e){ alert("json格式錯誤"); } }); }); function jsonToControl(jsonObj) { $("#divShow").empty(); $.each(jsonObj, function (index, item) { var control = null; var title = $("<label />"); switch (item.type) { case "textbox": control = createTextBox(); break; case "select": control = createSelect(item); break; case "password": control = createPassword(); break; //------------------------------ // 其它控件在這里加代碼 //------------------------------ } if (item.title != null) { title.text(item.title); } if (control != null) { control = setAttritube(control, item); $("#divShow").append(title); $("#divShow").append(control); $("#divShow").append("<br/>"); } }) } //設(shè)置控件的樣式 function setAttritube(control, item) { if (item.width != null) { control.width(item.width); } //-------------------------------- // 其他樣式在這里加代碼 //-------------------------------- return control; } //創(chuàng)建TextBox function createTextBox() { return $("<input type='textbox' />"); } //創(chuàng)建密碼框 function createPassword() { return $("<input type='password'/>"); } //創(chuàng)建Select function createSelect(item) { var c = $("<select></select>"); if(item.items != null ){ $.each(item.items,function(index,i){ $("<option value='"+i.key+"' checked='checked'>"+i.value+"</option>").appendTo(c); }) } return c; }
非常感謝各位抽空看完,。如果有任何意見或建議,請留言,。
轉(zhuǎn)載請指明出處 張*權(quán),。
來自: 昵稱10504424 > 《Jquery》
0條評論
發(fā)表
請遵守用戶 評論公約
為所有的textbox控件增加onblur事件
為所有的textbox控件增加onblur事件.
刷網(wǎng)課小玩意
JSON對象遍歷
JSON對象遍歷。// 遍歷簡單json對象 function traverseJsonSimpleObj(){ var jsonObj = {"name": "kevin", "age": 27, "sex": "男", "city&qu...
jquery Ajax 全局調(diào)用封裝
jQuery.ax=function(url, data, async, type, dataType, successfn, errorfn) {async = (async==null || async=="" || typeof(async)=="undefined")?dataType = (dataType==null |...
基于原生的 html css js php ajax做的一個 web登錄和注冊系統(tǒng)(帶發(fā)郵件功能)
//開啟會話 4 5 /* 6 驗(yàn)證 $_SESSION["user"]會話 記錄 是否存在 7 返回布爾值 8 */ 9 10 11 //如果$_SESSION["...
getJSON get方法傳輸數(shù)據(jù)
經(jīng)典C# ListBox操作實(shí)況
Winform控件學(xué)習(xí)
Add("全選(Ctrl+A)"); ms.Items.Add("復(fù)制(Ctrl+C)"); ms.Items.Add("粘貼(Ctrl+V)"); ms.Items.Add("刪除(Delete)"); ms.ItemClicked += new ToolStripItemC...
在ASP.NET MVC中使用DropDownList
由于TextBox的id和name屬性的值與ViewData中的某一項(xiàng)同名(均為Name),,因此TextBox的value屬性的值將自動綁定為ViewData中Name項(xiàng)的值,。如果ViewData和ViewData.Model中同時存在Name,則優(yōu)先使用ViewDa...
微信掃碼,,在手機(jī)上查看選中內(nèi)容
微信掃碼,在手機(jī)上查看選中內(nèi)容