I made a search script which searches for "Hallow" and alerts.
var Item = $('td > a:contains("Hallow")').text()
if(Item) {
alert(Item); }
This javascript is working for this html:
<html><body><div style="Padding:10px;">
<table width="469" cellspacing="0" cellpadding="2" border="0">
<tbody>
<tr valign="top">
<td width="313"> <img width="11" height="10" src="graphics/Default/Miscellaneous/weight.gif" alt="Yük: 3" title="Yük: 3">
<a href="CharacterDetails.asp?action=ViewItemDetails&ItemTypeiD=236&ItemID=100084253&CharacterID=53845">Kovboy çizmeleri</a> </td>
<td width="140" align="right"> </td>
</tr>
<tr valign="top">
<td width="313"> <img width="11" height="10" src="graphics/Default/Miscellaneous/weight.gif" alt="Yük: 5" title="Yük: 5">
<a href="CharacterDetails.asp?action=ViewItemDetails&ItemTypeiD=168&ItemID=68615745&CharacterID=53845">Halloween Canavar Maskesi</a>
</td>
<td width="140" align="right">
</td>
</tr>
</tbody></table>
<table width="469" cellspacing="0" cellpadding="3" border="0">
</table>
<br>
<br>
</div></body></html>
开发者_运维知识库
But sometimes item is secured. And html is like this:
<html><body><div style="Padding:10px;">
<table width="469" cellspacing="0" cellpadding="2" border="0">
<tbody>
<tr valign="top">
<td width="313"> <img width="11" height="10" src="graphics/Default/Miscellaneous/weight.gif" alt="Yük: 3" title="Yük: 3">
<a href="CharacterDetails.asp?action=ViewItemDetails&ItemTypeiD=236&ItemID=100084253&CharacterID=53845">Kovboy çizmeleri</a> </td>
<td width="140" align="right"> </td>
</tr>
<tr valign="top">
<td width="313"> <img width="11" height="10" src="graphics/Default/Miscellaneous/weight.gif" alt="Yük: 5" title="Yük: 5">
<a href="CharacterDetails.asp?action=ViewItemDetails&ItemTypeiD=168&ItemID=68615745&CharacterID=53845">Halloween Canavar Maskesi</a>
</td>
<td width="140" align="right">
Secured
</td>
</tr>
</tbody></table>
<table width="469" cellspacing="0" cellpadding="3" border="0">
</table>
<br>
<br>
</div></body></html>
I dont want my javascript to alert me if item is secured.
Function must be like that
var Item = $('td > a:contains("Hallow")').text()
var Itemsecured = (A code)
if(Itemsecured) {
}
else {
alert(Item)
}
I need the correct version of this code.
And this is important: I have two items, one is secured other is not. Javascript must alert me.
Don't store semantic information in a sibling; add a class.
var Contents = $('td:not(".secured") a:contains("Hallow")').text()
if( Contents ) alert( Contents )
$('td > a:contains("Hallow")').each(function(){
if($(this).parent().next('td').text() == 'Secured') {
// actions for secured item
}
else {
alert($(this).text());
}
});
精彩评论