加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Jquery .serialize()不处理下拉列表的值?

发布时间:2020-12-13 18:12:28 所属栏目:PHP教程 来源:网络整理
导读:我认为这应该是一个简单的事情,但由于某种原因,除了下拉列表的选定值之外,我的所有表单值都被序列化了,表格如下: form id="contactform" label for="name"Name/label input type="text" id=name name=name placeholder="First and last name" tabindex="1"
我认为这应该是一个简单的事情,但由于某种原因,除了下拉列表的选定值之外,我的所有表单值都被序列化了,表格如下:
<form id="contactform">
    <label for="name">Name</label> 
    <input type="text" id=name name=name placeholder="First and last name" tabindex="1" />

    <label for="phonenumber">Phone Number</label> 
    <input type="text" id=phonenumber name=phonenumber placeholder="Please enter your phone number" tabindex="2" />

    <label for="email">Email</label> 
    <input type="text" id=email name=email placeholder="example@domain.com" tabindex="3" />

    <label for="dropdown">Please Confirm:</label> 
        <select>
            <option value="question" selected="selected">I have a question</option>
            <option value="attending">I am attending</option>
            <option value="not-attending">I am not attending</option>
        </select>


    <label for="comment">Your Message</label>
        <textarea name="comment" id=comment name=comment placeholder="Enter something here,can't think" tabindex="5"></textarea> 

    <input name="submit" type="submit" id="submit" tabindex="6" value="Send Message"/>

</form>

这就是我如何序列化它:

$('#contactform').submit(function() {
    var query = $(this).serialize();

    $.ajax({
        type: "POST",url: "send.php",data: query,success: function(data) { // rest of function

最后我用来将值设置为变量的PHP位是:

$dropdown     = $_POST['dropdown'];

一个示例标题是name = sgrggr& phonenumber = 55555555555& email=me@me.comu0026amp; comment = quick test所以我不知道为什么下拉值没有被提取.

谢谢你的帮助.

您的下拉列表需要提交包含的name属性.
<select name="dropdown">
        <option value="question" selected="selected">I have a question</option>
        <option value="attending">I am attending</option>
        <option value="not-attending">I am not attending</option>
    </select>

希望这可以帮助!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读