尝试使用 .replaceWith() 替换;
你好,我是新来的,没有看到任何像我的问题一样的东西。听起来可能很简单,但似乎行不通。我正在尝试用其他一些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将代码包装在
ready
处理程序中:You need to wrap your code in
ready
handler: