我正在从onclick向fancybox模式打开一个隐藏表单。

的HTML:

<p class="btn btn-mini btn-success verify_form" id="<? echo $article_id; ?>" style="float:right; margin:4px;"> Verify</p>

<div style="display:none;" class="verify_the_form">
    <form id="article_check">
        <div>Enter Website Address of the Article you Wrote:
        <input type="hidden" id="id" value="" />
        <input type="text" id="article_url" style="width: 35%; margin-left: 10px;" value="" />
        <input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;" tabindex="-1" />
    </form>
</div>

jQuery的:
$(document).ready(function () {
    $(".verify_form").click(function () {
        var theid = $(this).attr('id');
        $('#id').val(theid);
        $.fancybox(
            $('.verify_the_form').html(),
            {
                'fitToView'         : true,
                'autoScale'         : true,
                'autoSize'          : true,
                'closeClick'        : false,
                'openEffect'        : 'elastic',
                'closeEffect'       : 'elastic',
            }
        );
    });

然后,我尝试使用jquery / ajax处理表单:
    $('#article_check').submit(function(event) {
        event.preventDefault();
        var theid = $('#id').val();
        var theurl = $('#article_url').val();
        alert(theurl);
        alert(theid);
        $.ajax({
            'url': '/includes/article_check.php',
            'type': 'get',
            'data': {
                'article_url': theurl,
                'id': theid
            },
            'success': function (data) {
                $('#article_check').append(data);
                return;
            },
            'error': function (request, status, error) {
                return;
            }
        });
    });
});

问题似乎是,fancybox的工作方式实际上是在页面上重绘表单....制作两个具有匹配ID的表单,并且由于没有元素应该具有多个ID,因此jquery混淆了使用,并且默认为隐藏形式的值。

更简单地说,变量theurl始终返回为空。

我正在寻找一种从用户提交的表单中获取$('#article_url')。val()的方法。

问题的示例网址

http://new.adsactlyhits.com/ae/example.html

最佳答案

当我找到自己的答案时,我会爱我,但讨厌我可能会浪费人们的时间。

我的解决方案相当基础,我不得不使用(this).find()从提交的表单中专门调用值。

var theid = $(this).find('#id').val();
var theurl = $(this).find('#article_url').val();

10-05 20:50
查看更多