2010-06-21 75 views
1

我正在尝试在下面的网页上添加“提供报价”按钮,以便人们可以点击并填写模式弹出窗体,然后通过电子邮件发送其详细信息:http://www.colincooke.com/coinpages/pennies_offer.html在HTML中使用Javascript/jQuery可变打印

该模式工作正常,但我似乎无法得到在HTML中输出的变量。

在这个页面是一个表行HTML代码:

<tr> 
<td></td> 
    <td class="date">1967</td> 
    <td class="desc">(F257 Dies 3+J. S4157). BU Full Lustre</td> 
    <td class="price">&pound;0.20</td> 
    <td class="nogrey"><a href="http://ww6.aitsafe.com/cf/add.cfm?userid=8935970&product=Item+714.+1d+1967+BU+Full+Lustre&price=0.20&return=http%3A%2F%2Fwww.colincooke.com%2Fcoinpages%2Fpennies.html" target="_self"><div class="cart-button"></div></a><a href="#dialog1" name="modal"><div class="offer-button"></div></a></td> 
</tr> 

这是JavaScript/jQuery的代码,以使一个模式弹出,并从按钮点击获取值 - 模态的东西不是我的代码 - 只存储变量的东西(很可能是更优雅:

<script type="text/javascript"> 
$(document).ready(

function() 
{ 
    $.localScroll(); 
    $("table.stocktable a.coinpic").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false }); 

    $("div.offer-button").click(function(){ 

    // add item text to variables 


           // THIS IS MY (amateur!) CODE BLOCK BELOW: 

    var itemDate = $(this).parent().parent().parent().children("td.date").text(); 
    var itemDescription = $(this).parent().parent().parent().children("td.desc").text(); 
    var itemPrice = $(this).parent().parent().parent().children("td.price").text(); 
    }); 

            // Is there a better/more direct way of doing the above? It currently works - but could be neater I think. 


    // MODAL BELOW 
    //select all the a tag with name equal to modal 
$('a[name=modal]').click(function(e) { 
    //Cancel the link behavior 
    e.preventDefault(); 

    //Get the A tag 
    var id = $(this).attr('href'); 

    //Get the screen height and width 
    var maskHeight = $(document).height(); 
    var maskWidth = $(window).width(); 

    //Set heigth and width to mask to fill up the whole screen 
    $('#mask').css({'width':maskWidth,'height':maskHeight}); 

    //transition effect 

    $('#mask').fadeTo("medium",0.8); 

    //Get the window height and width 
    var winH = $(window).height(); 
    var winW = $(window).width(); 

    //Set the popup window to center 
    $(id).css('top', winH/2-$(id).height()/2); 
    $(id).css('left', winW/2-$(id).width()/2); 

    //transition effect 
    $(id).fadeIn(250); 

}); 

//if close button is clicked 
$('.window .close').click(function (e) { 
    //Cancel the link behavior 
    e.preventDefault(); 

    $('#mask').hide(); 
    $('.window').hide(); 
}); 

//if mask is clicked 
$('#mask').click(function() { 
    $(this).hide(); 
    $('.window').hide(); 
}); 




} 
); 
</script> 

我觉得我已经成功地获取存储的产品图片,描述和价格变量(我试过报警和它似乎工作),但我想现在在模态窗口中打印变量显示出来。

即它说:

“你做的报价为:itemDate,itemDescription,ITEMPRICE”

的模式弹出使用页面上此代码:

<div id="boxes"> 
<!-- Start of Login Dialog --> 
<div id="dialog1" class="window"> 
    <div class="d-header"> 

    //I entered this message 
    You are making an offer for: 

    <input type="text" value="username"/><br/> 
    <input type="password" value="Password" />  
    </div> 
    <div class="d-blank"></div> 
    <div class="d-login"><input name="Login" type="button" value="Login" /></div> 
</div> 
<!-- End of Login Dialog --> 
</div> 

我试过使用:

You are making an offer for: 

<script language="javascript"> 
document.write (itemDate); 
</script> 

但是,对于某些人来说很明显的原因,这是行不通的。我想可能存储在jQuery中的变量可能不在该代码之外。如何在HTML模式表单的正确位置输出由itemDate,itemDescription和itemPrice存储的jQuery变量?

我已经使用了“在HTML中打印jQuery变量”,但找不到任何相关的东西。这要么太明显,要么不可能?

任何帮助,将不胜感激。

非常感谢

回答

2

如果我是你,我会抬头jQuery的文档中的附加/添加功能。

http://api.jquery.com/append/

http://api.jquery.com/prepend/

+0

好了,我废话,但是这是我试过,我知道它的基本javasript但嘿,我leraning:

你快把的报价为:

它不起作用。我应该如何(!)追加变量itemDate,即如何正确引用它? 感谢您的链接 - 热爱文档! – alsheron 2010-06-21 11:06:34

+0

想这太:

你快把的报价为:

alsheron 2010-06-21 11:13:41

+0

好吧,想我固定它:需要的: $(文件)。就绪( \t \t()函数 \t { 闭位 难道这总是需要引用jQuery的变量?或者是否有办法在全局声明它们? – alsheron 2010-06-21 11:16:23