document.getelementbyid无法获取textcontent

时间:2013-06-06 11:22:13

标签: jquery ajax xhtml

基于我在互联网上的搜索,我发现我必须在我的代码中设置一个onclick事件,所以我已经改变了jQuery函数,以便在下面点击时调用:

$.fn.addcart = function(item) {       
    alert ("im running ");
    // Create a new AJAXPaypalCart Object
    var cart = $('#cart').DCAJAXPaypalCart({
        width:600,
        autoOpenWhenAdd:true,
        openNewCheckOutWindow:true,
        //themeColor:'#333',
        //themeDarkColor:'#FFF',
        header:'Globuy Shopping Cart',
        footer:'We accpet paypal, visa and master card, Sberbank, Bank of China, Persian Bank',
        paypalOptions:{
            business:'tsangwl@digicrafts.com.hk',
            page_style:'digicrafts'
        }
    });        

    // Add the button
    cart.addBuyButton("#macbook",{
        name:"test", 
        // Item name appear on the cart
        thumbnail:'media/macbook.jpg',      // Thumbnail path of the item (Optional)
        price : $('#pricetag').text(), 
        // Cost of the item
        shipping:20             // Shipping cost for the item (Optional)
    });

    // For code highlight
    prettyPrint();
};

这里是PHP动态生成的购物车

 while($row = mysqli_fetch_array($result))
            {
$pic =  'image/'.$row['2'];
echo "<li><div class='prod_boxpage'>
    <div class='center_prod_box'>
      <div class='product_title'><a href='http://www.free-css.com/'>Makita 156 MX-VL</a>    </div>
      <div class='product_img'><a   href='http://www.free-css.com/'><img src='".$pic."' alt='".htmlspecialchars($row['1'])."' width='50' height='50' class='pngfix' /></a></div>

      <div class='prod_price'><span class='reduce'>350$</span> <span class='price'><a id='pricetag'>270</a>$</span></div>
    </div>
    <div class='prod_details_tab'> 


    <div class='caption'>
        <div class='text'>
             <div class='sub'>



              </div>
       </div>
          <div class='button' id='macbook' onClick='$(this).addcart('item');'><a class='prod_buy' >Add to Cart</a> <a class='prod_details'>Details</a> </div>
      </div>




    </div>
  </div>

      </li>

我目前的问题是我无法在点击时运行jQuery函数。我的onclick传递参数有什么问题吗?它应该将价格从价格加到购物车中。请帮忙。

2 个答案:

答案 0 :(得分:4)

尝试使用jQuery:

...
price : $('#pricetag').text(), // document.getElementById("pricetag").textContent,
...

答案 1 :(得分:0)

这个jQuery不会工作吗?

$('#pricetag').val();