1

我在 Joomla 中使用了厚盒组件。我正在使用 jQuery ajax 提交表单,但在单击提交按钮后 jQuery 没有获取值。我使用并创建了 script.js 文件,其中包含:

jQuery(document).ready(function(){
jQuery('.wp_btn').click(function() {
    var id = $j(this).attr('id');
    var url = $j(this).attr('value');
    if (document.cookie.indexOf('visited=true') == -1) {
        var fifteenDays = 1000*60*60*24*15;
        var expires = new Date((new Date()).valueOf() +  fifteenDays);
        document.cookie = "visited=true;expires=" +  expires.toUTCString();
        jQuery("#dwnlnk").val(url);
        TB_show('', '/#TB_inline?KeepThis=true&id=9876asdvfrty54321&height=250&width=350&inlineId=mypopup&caption=Subscription', '');

    }else{
        window.location = url;
    }
});
//
jQuery(document).on('submit', '#subscription',function(){
    return false; 
});

    jQuery(document).on('click', '#btnSubmit',function(){

            var url = jQuery('#dwnlnk').val();

            var txtname = $j('input[name=txtname]').val();
            var txtemail = $j('input[name=txtemail]').val();

            jQuery.ajax({  
                type: 'POST',
                url: 'whitepapers/',
                data: jQuery('#frmsubscription').serialize(),
                success: function(data) {
                    alert(data);
                    //if(data == 'true') {
                        window.location = url;
                    //}
                }
            });
          });//end click
});

我已经尝试过document.getElementById('txtname').value,但它没有获得文本框的价值。当我输入静态值时,它的获取值。

4

1 回答 1

0

您必须使用 jQuery 或 $ 来选择一个元素。

尝试这个

var txtname = jQuery('input[name="txtname"]').val();
var txtemail = jQuery('input[name="txtemail"]').val();

或者

var txtname = $('input[name="txtname"]').val();
var txtemail = $('input[name="txtemail"]').val();
于 2013-05-30T10:09:31.437 回答