0

你好,我是新来的,没有看到任何像我的问题一样的东西。听起来可能很简单,但似乎行不通。我正在尝试用其他 html 替换 id='CAShip' 的 div。

这是代码。jQuery:

<script type="text/javascript">
$('#CAShip').click(function(){
    $('#CAShip').replaceWith('New HTML code');
});
</script>

这是开始的html:

<div id="CAShip">
<table class="contentpaneopen">
  <tr>
    <td class="contentheading" width="100%">Canadian Customers Click Here Before Ordering!
    </td>
  </tr>
</table>
</div>

这是我要替换它的 HTML:

<div>
<table class="contentpaneopen">
  <tr>
    <td class="contentheading" width="100%">Attention Canadian Customers!
    </td>
  </tr>
</table>

<table class="contentpaneopen">
  <tr>
    <td valign="top" >
    <span class="body">Please note that there are fees associated with shipping to Canada from the US that are <b><u><i><font color="red">NOT</font></i></u></b> included in the cost of the shipping or the cost of the unit. These cost are to be paid for by the purchaser. Here are some tips for shipping to Canada:
    <br />
    <br />
    -USPS methods are cheap but very unreliable. <b>Border fees</b> are not charged using USPS, only UPS or Fed Ex (which are the most reliable).
    <br />
    -<b>Customs fees</b> can sometime run <b>up to 50%</b> of the purchase price (UPS/FedEx).
    <br />
    -Smart Strips are available from a Canadian dealer. Visit our <a href="index.php?Itemid=146" title="Store Locator" target="_blank">Store Locator</a> to find a local seller.
    <br />
    -Customers with a UPS or FedEx account may ship on their account and assume all fees with no delays.
    <br />
    -Canadian customers selecting UPS or FedEx will have to pick the package up at their local station and pay the fees. So you order it online, but still have to drive and pay to pick it up unless you used your own UPS/Fed Ex account.</span>
    </td>
  </tr>
</table>
</div>

有什么建议么?

4

1 回答 1

2

您需要将代码包装在ready处理程序中:

<script type="text/javascript">
$(function(){
  $('#CAShip').click(function(){
    $('#CAShip').replaceWith('New HTML code');
  });
});
</script>
于 2011-01-20T18:18:38.827 回答