尝试使用 .replaceWith() 替换
;

发布于 2024-10-13 05:19:38 字数 2229 浏览 1 评论 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>

有什么建议吗?

Hello I am new here and didn't see anything quite like my question. It may sound simple but it doesn't seem to work. I am trying to replace a div with id='CAShip' with some other html.

Here is the code.
The jquery:

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

This is the starting html:

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

This is the HTML I want to replace it with:

<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>

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹊巢 2024-10-20 05:19:38

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

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

You need to wrap your code in ready handler:

<script type="text/javascript">
$(function(){
  $('#CAShip').click(function(){
    $('#CAShip').replaceWith('New HTML code');
  });
});
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文