dongxinjun3944 2015-04-23 16:30
浏览 48
已采纳

如何从JS或Mootools中的表单获取数组发送它而不是PHP?

IMAGE OF FORM

HTML:

<select name="birthdate[day]" id="birthdate-day" class="date_class">
    <option value="0"> </option>
     .....
</select>
<select name="birthdate[month]" id="birthdate-month" class="date_class">
    <option value="0"></option>
    ..........
</select>
<select name="birthdate[year]" id="birthdate-year" class="date_class">
    <option value="0"> </option>
    <option value="2015">2015</option>
     ....
</select>

I tried to get data this way, but it didn't works:

var birthdate = $contactForm.getElement('select[name="birthdate"]').getProperty('value');

How to get array from form in JS or Mootools to send it than to PHP? Will be send data to PHP in JSON format.

  • 写回答

1条回答 默认 最新

  • dongshuo1856 2015-04-23 17:01
    关注

    The problem is with your selector. You are giving a partial name, but with the syntax you are using it expects the complete name.

    So try something like:

    var birthdate = $contactForm.getElement('select[name^="birthdate"]').getProperty('value');
    

    However this is only going to get you the first element that matches.

    So with MooTools, you could do something like:

    $$('select[name^=birthdate]')
    

    Or in JS:

    document.querySelectorAll('select[name^=birthdate]')
    

    Hope that helps

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 软件定义网络mininet和onos控制器问题
  • ¥15 微信小程序 用oss下载 aliyun-oss-sdk-6.18.0.min client报错
  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。