2011-07-17 78 views
-2

我製作了一個搜索腳本,用於搜索「萬聖節」和警報。搜索內容並提醒是否

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

這個JavaScript正在爲這個網站:

<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必須提醒我。

+1

''真的嗎?這是你的標記? – user113716

+0

İt是複製錯誤。 –

+0

爲什麼你的代碼在我的屏幕中間?然後你的Javascript沒有縮進?如果你不能讓你的帖子易於閱讀,那麼我不會被困擾,以回答它:( –

回答

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

我有一個問題,總是提醒($(this).tex());? –

+0

不是,它不是警告:http:// jsfiddle。 net/FrE9Q/1 /不會提示:http://jsfiddle.net/AztEe/。但是你最好用css類標記安全項目。 – Hnatt

+0

http://jsfiddle.net/FrE9Q/2/這是真實的html version。請幫我編輯你的代碼 –

1

不要將語義信息存儲在同級中;添加一個類。

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

這是一個Greasemonkey應用程序。 OP不控制頁面生成,也不控制服務器。 GM腳本在加載後測試並修改頁面。 –