在我的asp.MVC應用程式中,有兩個單選按鈕和一個組合框。
有人點擊radiobutton 1,組合框加載一些資料。如果點擊radiobutton 2,則向組合框加載不同的資料。腳本是用ajax撰寫的。
當用戶點擊改變了單選按鈕時,該代碼作業正常。但是對于一些用戶,我隱藏了radiobutton 2。所以對他們來說,只有單選按鈕1是可見的,但在這種情況下,沒有資料加載到組合框中。
我還想知道,如果在加載視圖時,有輻射按鈕被選中,需要向組合框獲取相關資料。
。$(function() {
$('[id*=ddlTopEmployees]').select2().next().hide()
$('[id*=Approve_Type]').change(function() {
setDropDownProductsA($(this).val())
});
});
function setDropDownProductsA(xVal) {
try {
$("#ddlEmployees").empty().trigger("chang" /span>)
$.ajax({
url: './FindProductTypes',
type: 'POST'。
dataType: 'json',
cache: false,
async: false,
data: {
AppLvlId: xVal
},
success: function(data) {
if (data.Success == true) {
$("#ddlEmployees"/span>).select2({
width: '100%'。
data: JSON.parse(data.items)
});
}
}
});
} catch (err) {
console.log(err.message)
}
}
<script src="https://cdnjs. cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
uj5u.com熱心網友回復:
使用點擊而不是改變
$('[id*=Approve_Type]') 。 click(function() {
setDropDownProductsA($(this).val())
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/323827.html
標籤:
上一篇:如何從文本中提取測量和/或單位?
