【问题标题】:document.getelementbyid isnt able to get textcontentdocument.getelementbyid 无法获取文本内容
【发布时间】:2013-06-06 11:22:13
【问题描述】:

根据我在互联网上的搜索,我发现我必须为我的代码设置一个 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 传递参数有什么问题吗?它应该将价格标签中的价格添加到购物车中。请帮忙。

【问题讨论】:

  • 您的代码运行良好 (jsfiddle.net/6KskK/2)。您是否收到任何错误消息?
  • 没有错误,什么都没有发生,应该是打开弹出购物车并添加商品,

标签: jquery ajax xhtml


【解决方案1】:

尝试使用 jQuery:

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

【讨论】:

  • 如果上述情况失败,您可以使用 .html()
  • 我已将调用ajax函数的方法更改为onclick,但点击时不会调用该函数,我还在试图找出原因?请在这里给我一些建议,谢谢
【解决方案2】:

这个 jQuery 不行吗?

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

【讨论】:

  • 这不起作用,因为它是一个被选中的a 元素。你可以改用parseFloat($(this).text())
  • 啊,我没听懂。根据他的使用方式,我愣了一下,以为是span
猜你喜欢
  • 2015-09-03
  • 1970-01-01
  • 1970-01-01
  • 2012-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-05
  • 1970-01-01
相关资源
最近更新 更多