Javascript变量,发送到PHP变量

问题描述:

我有从MySQL数据库拉动产品的动态列表。在列表中有一个现在联系按钮,我正在使用jQuery的Modal脚本弹出与窗体。Javascript变量,发送到PHP变量

我的问题是试图将产品信息传递变量是弹出窗口。

我想用相对 attribue这样加入品牌和型号名称:

<a href="#" class="contact_now" rel="<?=$sku_brandname;?> <?=$sku_modelname;?>">Contact Now!</a> 

,然后使用Javascript我可以这样做:

$(".contact_now").click(function(){ 

    var rel = $(this).attr('rel'); 
    alert(rel); 

其中工程完美,但在我的Popup Div我不知道如何让这个JavaScript的rel变量输出它。

<p>Fill out the form below to inquire about the <strong>{ rel value here }</strong>. We will get back to you as soon as possible.</p> 

我不知道该怎么做。如果任何人有任何想法或建议,我将不胜感激。

谢谢!

+0

该模式插件,你呢? –

+0

我用这个:http://yensdesign.com/2008/09/how-to-create-a-stunning-and-smooth-popup-using-jquery/ – Drew

+0

所以你要像'$(“#popupContact强“).text(rel)' –

几件事。首先,如果你想将数据存储在某些节点上,你最好还是使用数据属性,像这样:

<a href="#" class="contact_now" data-brand-name="<?=$sku_brandname;?>" data=-model-name="<?=$sku_modelname;?>">Contact</a> 

然后,您可以使用jQuery,让他们像这样:

$(this).data("brandName"); 

至于将变量发送到PHP的东西,你应该改变当你打开弹出窗口JavaScript的值。 (如果它不在同一页面上,请在评论中说)。要做到这一点,你可以给span一个类,并修改它,然后显示弹出窗口。

<p>Fill out the form below to inquire about the <span class="product"></span> We'll get back to you ASAP.</p> 

然后在jQuery的:

$(".product").text($(this).data("brandName")); 
//Show popup 
+0

太棒了,正是我需要的。非常感谢! – Drew

+0

非常欢迎。 –

+0

downvoter可以提供一些反馈吗? –