搜索内容并提醒是否

时间:2011-07-17 15:18:49

标签: javascript jquery firefox greasemonkey

我制作了一个搜索脚本,搜索“Hallow”并发出警报。

var Item = $('td > a:contains("Hallow")').text()
if(Item) {
alert(Item); }

这个javascript适用于这个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>

但有时项目是安全的。而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">
Secured
</td>
                    </tr>

                    </tbody></table>
                  <table width="469" cellspacing="0" cellpadding="3" border="0">
                    </table>


      <br>
      <br>
      </div></body></html>

如果项目安全,我不希望我的javascript提醒我。

功能必须像那样

var Item = $('td > a:contains("Hallow")').text()
var Itemsecured = (A code)
if(Itemsecured) {
}
else {
alert(Item)
}

我需要此代码的正确版本。

这很重要:我有两个项目,一个是安全的,另一个不是。 Javascript必须提醒我。

2 个答案:

答案 0 :(得分:1)

不要将语义信息存储在兄弟姐妹中;添加一个类。

var Contents = $('td:not(".secured") a:contains("Hallow")').text()
if( Contents ) alert( Contents )

答案 1 :(得分:0)

$('td > a:contains("Hallow")').each(function(){
    if($(this).parent().next('td').text() == 'Secured') {
      // actions for secured item
    }
    else {
      alert($(this).text());
    }
});