推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
yakczh

提交的表单后,后台返回post参数的json,解析json以后如果根据名字找到相应的dom元素呢?

  •  
  •   yakczh · May 4, 2013 · 3597 views
    This topic created in 4783 days ago, the information mentioned may be changed or developed.
    比如表单是
    <form action="" name="f">

    <input type="text" name="aa" />

    <input type="radio" name="cc" value="1">1
    <input type="radio" name="cc" value="2" checked >2
    <input type="checkbox" name="dd[]" value="a">a
    <input type="checkbox" name="dd[]" checked value="b">b
    </form>


    后台返回的json里的名字是 aa,cc,dd

    然后根据解析josn后得到aa,cc,dd反查到dom节点,还是挺麻烦的

    typeof typeof document.f.aa

    typeof typeof document.f.cc
     
    都返回object  但是一个是单项,一个是列表
    对于input 是 document.f.aa.value 对于radio,要和 document.f.cc[0].value
    还有checkbox  要用 document.f['dd[]']这样才能找到或者 document.getElementsByName('dd[]')
    只有在名字后面加'[]'去试探吗?有其他方法吗?
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5837 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 02:21 · PVG 10:21 · LAX 19:21 · JFK 22:21
    ♥ Do have faith in what you're doing.