1

我的初始表单计算变量 $finallowamount 和 $finalhighamount,但我似乎无法将这些变量的值传递给我的 jQuery 联系人 javascript 文件(下面的代码)。任何帮助将不胜感激。谢谢。

    $(function() {
$('a.email').click(function(event) {
    event.preventDefault();

    $('body').append('<div id="popupshadow"></div><div id="popup"></div>');
    $('#popupshadow').css({opacity:0}).animate({opacity:0.7},1000);
    $('#popup').css({opacity:0}).delay(1200).animate({opacity:1},800);
    $('#popup').html('<form class="contact" action="#" method="post"><table class="contact"><tr><td class="input-name">Name:</td><td><input type="text" name="name" size="25" /></td></tr><tr><td class="input-email">Email:</td><td><input type="email" name="email" size="25" /></td></tr><tr><td class="input-phone">Phone:</td><td><input type="phone" name="phone" size="25" /></td></tr><tr><td></td><td><input type="submit" value="Send" /></td></tr></table><input type="hidden" name="to" value="noahldavis@gmail.com"></form>');
    $('form.contact').submit(function(event) {
        $('form.contact td').css('color','#000000');

        var name = $('form.contact input[name="name"]').val();
        var email = $('form.contact input[name="email"]').val();
        var phone = $('form.contact input[name="phone"]').val();
        var to = $('form.contact input[name="to"]').val();

        var valid = true;
        if(name == "") 

        {
            valid = false;
            $('td.input-name').css('color','#FF0000');
        }
        if(email == "" && phone == "")
            valid = false;
        if(email == "")
            $('td.input-email').css('color','#FF0000');
        if(phone == "")
            $('td.input-phone').css('color','#FF0000');

        var message = 'message';
        var paymentstreamtype = $("#ssq_rc_general input[type=radio]:checked").val();
        var finallowamount = $("#finallowamount").html();
        var finalhighamount = $("#finalhighamount").html();


        if(valid) {
            $.ajax({url : 'contact.php',
                    data : {name : name,
                            email : email,
                            phone : phone,
                            message : message,
                            paymentstreamtype : paymentstreamtype,
                            finallowamount : finallowamount,
                            finalhighamount : finalhighamount,
                            to : to},
                    type : 'post',
                    success : function(data) {
                        $('#popup').html('<p style="text-align:center;">Your message has been sent.</p>');
                        $('#popup, #popupshadow').delay(1000).animate({opacity:0},500).delay(500).queue(function() { $(this).remove(); });
                    }
            });
        }
        event.preventDefault();
        return false;
    });
    $('#popupshadow, a.cancel').click(function(event) {
        $('#popup, #popupshadow').animate({opacity:0},500).delay(500).queue(function() { $(this).remove(); });
    });
});

});

4

1 回答 1

1

首先,javascript 在 web 客户端中运行,而 php 在您的服务器上运行。

如果您不想使用 php var,则必须让 source 将这些 var 替换为实际值。

如果这是一个 js 文件,您可以使用 php 包含此文件:

//loadjs.php
public function loadJs()
{
    if(extension_loaded('zlib')) {
        //check gzib
        ob_start('ob_gzhandler');
    }

    header ("content-type: application/javascript; charset: UTF-8");
    header ("cache-control: must-revalidate");
    $offset = 60 * 60 * 24;
    $expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT";
    header ($expire);
    ob_start("compress");
    $js = array(
        '0'=>array('/js/swf/swfupload.js'),
    );

    foreach($js as $key=>$value){
        foreach($value as $v){
            include $v;
        }
    }

    if(extension_loaded('zlib')){
        ob_end_flush();//flush all buffer content
    }
}
loadJs()

//then,load this js file in your html file:
<script src="loadjs.php" />
于 2012-09-05T02:28:27.057 回答