2010-10-15 37 views
0

我在jQuery中傳遞DOM節點後試圖做其他選擇。在這個例子中,我試圖展現一個「隱藏」的選擇框(變更通知後提交按鈕,我傳遞的形式元素,而不是SELECT元素:帶附加選擇器的jQuery DOM節點

<form id="UpdateRegistrationStatusForm"> 
    <select id="registration_status" onchange="AdjustRegistrationStatus(this.form)"> 
     <option value="1">approved</option> 
     <option value="2">cancelled</option> 
    </select> 
    <input id="registration_status_update" type="submit" style="display:none" value="update"/> 
</form> 

因此, jQuery的代碼,我想做的事情,但不工作看起來是這樣的......

function AdjustRegistrationStatus(myForm) 
{ 
    jQuery(myForm "#registration_status_update").show(); 
    if (jQuery(myForm "#registration_status").val() == 1) 
    { 
      //do some other things here... 
    } 
} 

我要開始一個FORM DOM對象,並添加額外的「串」選擇。任何幫助嗎?

回答

1

我懷疑你正在尋找find函數,但我有點困惑,因爲從屬元素有ID,所以你並不需要從表單開始。如果他們有一些其他的,非唯一的事情(如類),你可以這樣做:

var form = $('#UpdateRegistrationStatusForm'); 
form.find('.regupdate').show(); 
if (form.find('.regstatus').val() == 1) 
{ 
    //... 
} 

..但與標識有多少理由不給。