2013-03-07 127 views
-2

我有以下的下拉更改功能打

@Html.DropDownList("SalesChannelId", Model.SalesChannels, @AuctionControllerResource.SelectSalesChannel, new { id="salesChannel", required = "required" }) 

我有以下的Javascript

$('#salesChannel').change(function() { 
    var selectedSalesChannel = $("#salesChannel").val(); 
    var seenSalesChannel = $("#seenSalesChannelId").val(); 
    if (selectedSalesChannel == seenSalesChannel) { 
     $("#remarketingSiteList").show(); 
    } else { 
     $("#remarketingSiteList").hide(); 
    } 
}); 

但由於某些原因,當我在更改值這個代碼永遠不會被打落下。我在Firebug中放置了一個斷點,但沒有歡樂。我究竟做錯了什麼?

回答

1

你選擇錯了幫手FUNC指定Id

試試這個

$(document).ready(function(){ 
$('#SalesChannelId').change(function() { 
    var selectedSalesChannel = $("#SalesChannelId").val(); 
    var seenSalesChannel = $("#seenSalesChannelId").val(); 
    if (selectedSalesChannel == seenSalesChannel) { 
     $("#remarketingSiteList").show(); 
    } else { 
     $("#remarketingSiteList").hide(); 
    } 
}); 
}); 
3

嘗試

$("#SalesChannelId").change 

,而不是

$('#salesChannel').change 

因爲生成的ID是SalesChannelId

@Html.DropDownList("SalesChannelId"