use*_*498 3 javascript jquery html-table
我正在尝试找到包含图像的节点,然后在该图像的标签中找到特定的字符串.但我不知道在页面上何时会出现图像标记,除了它只出现在td被归类为的元素中bodyTextSmall.那应该让我在那里,对吗?
一切正常,直到我试图获得length该childNodes物业.见上面的一行.
这是正确的代码,还是有另一种方法可以找出某个特定内部是否td有某个img标签?我正在撕掉我留下的小头发,因为从我对JavaScript的了解很少,这就是它应该如何运作.
问题是我只通过img标签知道是否需要格式化td标签,而且我没有组装td标签,也无法直接进入网站的那一部分进行更改.我已经尝试过CSS选择器来查看我是否可以设置部分图像的样式,但是有一些我无法覆盖的内联样式.同样,这是我无法控制的网站的一部分.
<script type="text/javascript">
function getTables(dRef) {
var d = document;
var dMid = d.getElementById('mainContent');
var dTabs = dMid.getElementsByTagName('td');
// Attempts to load table cells...
for (var i = 0; i < dTabs.length; i++) {
// Attempts to detect the specific cell type...
if (dTabs[i].className == "bodyTextSmall") {
// Attempts to locate the parts inside this cell...
var myNodes = i.ChildNodes; // This part runs, but I can't get "ChildNodes.length" to work
// Attempts to notify the user...
alert(dTabs[i].className + ': ' + i);
}
}
}
window.onload = getTables;
</script>
Run Code Online (Sandbox Code Playgroud)
所以,现在我已经切换到jQuery,我遇到了同样的问题.我可以知道图像在哪里,但我对图像本身无能为力.
<script type="text/javascript">
function getTables() {
// Locates the correct container for images...
$('#mainContent img').each(function(idx, item) {
var tImgs = item.src;
if (tImgs.indexOf("-ds.") > 0) {
window.alert(tImgs);
$(this).append('Here is a message about the image.'); //nothing happens here
}
});
}
window.onload = getTables;
</script>
Run Code Online (Sandbox Code Playgroud)
同样,这个jQuery代码通过响应任何具有"-ds"的图像来响应.在src的任何地方.我无法得到任何其他事情.我知道$(img).append会影响每个图像,所以脚本能够做某事.
现在这已成为一个获得超出我想要的东西或根本没有任何东西的情况,它真的开始让我最后的紧张.