通过“.serialize()”获取价值的问题?

时间:2011-08-20 12:24:06

标签: javascript jquery

我希望点击#value(VALUE)后使用input:checkbox获取值.serialize()

示例: http://jsfiddle.net/tKBJ2/40/

$('#value').click(function(e){
        e.preventDefault();
    alert("this alert only after click on '#value'");
        $('.table_show tr').each(function(){
            if ($(this).prop('checked')) {
                var dataString = $('.table_show').serialize(); // This don't work
                alert(dataString);                
                $(this).parent().parent().fadeOut("slow");
                $.ajax({
                    type: "POST",
                    url: "http://localhost/admin/customer_size/delete",
                    data: dataString,
                    cache: false,
                    success: function(){
                    },
                    error: function(data){
                        alert('Load was performed.');
                    }
                })                
            }
        })
    });

1 个答案:

答案 0 :(得分:1)

serialize()用于从表单的输入中获取查询字符串,您应该检查选择器是否选择表单元素。

cf jquery doc:http://api.jquery.com/serialize/

将您的div table _ show封装在form中,并对此form进行序列化:

<form class="myForm">
  <div class="table_show">
    rest of your code
  </div>
</form>

然后在你的js:

var dataString = $('.myForm').serialize();