开发者

Searching a content and alert if

开发者 https://www.devze.com 2023-03-20 17:33 出处:网络
I made a search script which searches for \"Hallow\" and alerts. var Item = $(\'td > a:contains(\"Hallow\")\').text()

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">&nbsp;<img width="11" height="10" src="graphics/Default/Miscellaneous/weight.gif" alt="Yük: 3" title="Yük: 3">&nbsp;

                        <a href="CharacterDetails.asp?action=ViewItemDetails&amp;ItemTypeiD=236&amp;ItemID=100084253&amp;CharacterID=53845">Kovboy çizmeleri</a>                                                                                                                              </td>
                    <td width="140" align="right">  </td>
                </tr>



                    <tr valign="top">
                        <td width="313">&nbsp;<img width="11" height="10" src="graphics/Default/Miscellaneous/weight.gif" alt="Yük: 5" title="Yük: 5">&nbsp;

                        <a href="CharacterDetails.asp?action=ViewItemDetails&amp;ItemTypeiD=168&amp;ItemID=68615745&amp;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">&nbsp;<img width="11" height="10" src="graphics/Default/Miscellaneous/weight.gif" alt="Yük: 3" title="Yük: 3">&nbsp;

                            <a href="CharacterDetails.asp?action=ViewItemDetails&amp;ItemTypeiD=236&amp;ItemID=100084253&amp;CharacterID=53845">Kovboy çizmeleri</a>                                                                                                                              </td>
                        <td width="140" align="right">  </td>
                    </tr>



                        <tr valign="top">
                            <td width="313">&nbsp;<img width="11" height="10" src="graphics/Default/Miscellaneous/weight.gif" alt="Yük: 5" title="Yük: 5">&nbsp;

                            <a href="CharacterDetails.asp?action=ViewItemDetails&amp;ItemTypeiD=168&amp;ItemID=68615745&amp;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());
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消