我无法从 遍历 DOM到...?
概述
我非常感谢对此提供的任何帮助。我确信这很“容易”,但我无法弄清楚。我必须使用选择器来选择唯一的图像文件名。然后,我需要替换 ,它是
右侧的一列。 我有当前的
网站,我还制作了一个图表来帮助更好地解释这一点。检查以下两个链接: 网站:http://www.writeguard.com/catalog/Checks/LaserInkjet-Checks 图: http://goo.gl/Q3Uif
问题
上面网站的链接没有问题。我们的 oscommerce 中有一个“特许经营”自定义修改。只有拥有特定帐户的客户才能登录我需要帮助的地方。我制作的图表描述了这一点,很简单。为了让您了解我的“拼图”的所有“部分”,以下是我为主站点执行 .replaceWIth()
的方法。这个例子是针对顶行的...我需要修改的每一行都有一个。
$("a[href$=/Premium-Security-Laser-Check].smallTextLink").parent()
.replaceWith('<td class="productListing-data" style="border-left:1px solid #FFF; border-top:1px solid #FFF; border-bottom:1px solid #808080; border-right:1px solid #808080;"><div class="leftSide"><a href="http://www.writeguard.com/catalog/Checks/LaserInkjet-Checks/Premium-Security-Laser-Check" class="smallTextLink">Premium Security Laser Check</a><ul style="line-height: 1.5em; font-size: 11px; margin-left: -15px;"><li style="color:red;"><strong>Buy 500 Checks, Get 500 Free Special!</strong></li><li>More than 8 security features</li><li>Thermochromic Ink</li><li>8.5" x 11" sheet 24lb MICR paper</li><li>2 perforations @ 3.5" x 7"</li></ul><div class="moreInfoButtonsNew"><a href="http://www.writeguard.com/catalog/Checks/LaserInkjet-Checks/Premium-Security-Laser-Check" class="positive"><img src="http://writeguard.com/catalog/images/new_layout/icons/information.png" alt=""/>More Info</a></div></div><div class="rightSide"><p class="ourPrice">Starting At:<br>$39.50</p></div></td>');
我认为这根本没有效率。但就我现在遇到的这个问题而言,我需要能够执行我在顶部描述的操作。通过文件名选择 ,然后导航 DOM,以便我可以使用
.replaceWith()
来实现我上面描述的相同功能。我尝试了很多不同的选择器,但没有一个起作用。它总是最终将表数据放入表数据内,直到页面实际上有 10 英尺长。我不知道我哪里错了。
如有必要,我很乐意提供更多详细信息。显然我对 jQuery 不太有经验,我的方法可能是一场噩梦。我想尽快学习正确、有效的 jquery 编程方法。非常感谢您的帮助!
Overview
I greatly appreciate any help with this. I'm sure it's "easy" but I can't figure it out. I am having to use selectors to choose a unique image file name. I'm then needing to replace the <td>
that is one column to the right of the <td>
that the <img>
is in.
I have the current website and I also made a diagram to help explain this better. Check the following two links:
Website: http://www.writeguard.com/catalog/Checks/LaserInkjet-Checks
Diagram: http://goo.gl/Q3Uif
The Problem
The link to the website above doesn't have a problem. We have a "franchise" custom modification in our oscommerce. Only customers with certain accounts can log into where I'm needing help. The diagram I made describes it, simply enough. Just so you have all the "pieces" of my "puzzle", here is how I'm doing the .replaceWIth()
for the main site. This example is for the top row...I have one of these for every row I need to modify.
$("a[href$=/Premium-Security-Laser-Check].smallTextLink").parent()
.replaceWith('<td class="productListing-data" style="border-left:1px solid #FFF; border-top:1px solid #FFF; border-bottom:1px solid #808080; border-right:1px solid #808080;"><div class="leftSide"><a href="http://www.writeguard.com/catalog/Checks/LaserInkjet-Checks/Premium-Security-Laser-Check" class="smallTextLink">Premium Security Laser Check</a><ul style="line-height: 1.5em; font-size: 11px; margin-left: -15px;"><li style="color:red;"><strong>Buy 500 Checks, Get 500 Free Special!</strong></li><li>More than 8 security features</li><li>Thermochromic Ink</li><li>8.5" x 11" sheet 24lb MICR paper</li><li>2 perforations @ 3.5" x 7"</li></ul><div class="moreInfoButtonsNew"><a href="http://www.writeguard.com/catalog/Checks/LaserInkjet-Checks/Premium-Security-Laser-Check" class="positive"><img src="http://writeguard.com/catalog/images/new_layout/icons/information.png" alt=""/>More Info</a></div></div><div class="rightSide"><p class="ourPrice">Starting At:<br>$39.50</p></div></td>');
That is not efficient at all, I assume. But just for this problem I'm having now, I need to be able to do what I described at the top. Select the <img>
by it's filename, then navigate the DOM so I can use .replaceWith()
to achieve the same thing I described above. I've tried a lot of different selectors but none of them work. It always ends up making table data inside table data inside table data until the page is literally 10 feet long. I don't know where I'm going wrong.
I can happily provide more details if necessary. I'm obviously not very experienced with jQuery and my methods are probably a nightmare. I want to learn the correct, efficient way to program with jquery soon. THANK YOU VERY MUCH FOR YOUR HELP!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
选择器应该是:
并且您的表的结构是:
所以您的 jQuery 语句需要找到作为 td 的父级。 Parent() 返回 div。您希望parents('td:first') 获取作为td 元素的第一个父级。
The selector should be:
And the structure of your table, you have:
So your jQuery statement needs to find the parent that is a td. parent() is returning the div. You wants parents('td:first') to grab the first parent that is a td element.
我相信问题出在你的选择器上。
我不相信
$("a[href$=/Premium-Security-Laser-Check].smallTextLink")
实际上会抓住任何东西。试试这个:
如果有效,那么您应该能够更改您的选择器并让您的替换工作。
$('a.smallTextLink[href=/Premium-Security-Laser-Check]').parent()
.replaceWith('
开始价格:
39.50 美元
');
I believe the problem is with your selector.
I don't believe
$("a[href$=/Premium-Security-Laser-Check].smallTextLink")
will actually grab anything.Try this:
If that works, then you should be able to just change your selector and have your replacewith work.
$('a.smallTextLink[href=/Premium-Security-Laser-Check]').parent()
.replaceWith('<td class="productListing-data" style="border-left:1px solid #FFF; border-top:1px solid #FFF; border-bottom:1px solid #808080; border-right:1px solid #808080;"><div class="leftSide"><a href="http://www.writeguard.com/catalog/Checks/LaserInkjet-Checks/Premium-Security-Laser-Check" class="smallTextLink">Premium Security Laser Check</a><ul style="line-height: 1.5em; font-size: 11px; margin-left: -15px;"><li style="color:red;"><strong>Buy 500 Checks, Get 500 Free Special!</strong></li><li>More than 8 security features</li><li>Thermochromic Ink</li><li>8.5" x 11" sheet 24lb MICR paper</li><li>2 perforations @ 3.5" x 7"</li></ul><div class="moreInfoButtonsNew"><a href="http://www.writeguard.com/catalog/Checks/LaserInkjet-Checks/Premium-Security-Laser-Check" class="positive"><img src="http://writeguard.com/catalog/images/new_layout/icons/information.png" alt=""/>More Info</a></div></div><div class="rightSide"><p class="ourPrice">Starting At:<br>$39.50</p></div></td>');