2011-09-02 63 views
1

我有PHP代碼執行一個循環,在其內部會生成以下內容:隱藏以前輸入按鈕

echo "<input type=\"button\" event='$eventID' id=\"sendsomeone\" value=\"Send a family member\"/>"; 
echo "<span id='$eventID'></span>"; 

後來,我的JavaScript其中如下:

$('input:button').click(function() { 
    $(this).next("span").append('You clicked this button!'); 
} 

此代碼工作精細。但我想它也隱藏按鈕(但並不是所有的頁面上的按鈕)

我試着代碼嘴硬像

$(this).parent("input").hide(); 

$(this).prev("input").hide();

但我做不到不知道如何使它工作。

回答

2

看起來你已經在按鈕選擇器中使用$('input:button'),所以你有沒有試過這樣做?

$(this).hide(); 
+0

這些天,我將不再是貨物邪教編程,我會知道這些令人難以置信的簡單的事情。哇謝謝! – jeremy

+0

沒問題的人。你會得到它的竅門。 – slandau

0

你可能也想看看toggle這是有幫助的,因爲它泔水隱藏它,如果它是可見的,並顯示它,如果它不是:

$(this).toggle();