drcj64241 2016-03-22 23:34
浏览 92

从JSON api填充html表单元素的正确方法

I have an API returning a JSON object containing user settings. Before using it, I was used to filling fields with php:

 <input type="checkbox" <?php echo $checked ?>>

Now I have a JSON object and no PHP output. How to manipulate it to do the same?

I thought about using jquery to fill in elements on document.ready:

$(document).ready(function() {
  $('input').attr('checked', jsonobj.checked);
}

But something tells me that it's a bit hackish, is that the right way to do it?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 fluent的在模拟压强时使用希望得到一些建议
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services
    • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
    • ¥15 模糊pid与pid仿真结果几乎一样
    • ¥15 java的GUI的运用
    • ¥15 Web.config连不上数据库
    • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
    • ¥15 怎么配置广告联盟瀑布流
    • ¥15 Rstudio 保存代码闪退