我有一个html表,如下所示
<table id="searchResults" class="compact-table" width="100%">
<thead>
<th><label id="Revenue"></label></th>
<th></th>
</thead>
我正在命名列标题,如代码所示,但我希望这些列名称动态分配
我已经放置了一个名为收入的标签 对于该标签,我使用 Jquery 分配值,如下所示
var yearVal = $("#salesDashboardYearDropDown").val();
var monthVal = $('select#salesDashboardMonthDropDown :selected').text();
var revenueLastYear = (monthVal + ' ' + (yearVal - 1).toString()).toString();
$('#Revenue').html(revenueLastYear);
但未显示enter code here
答案 0 :(得分:1)
检查您在选择id
salesDashboardMonthDropDown elements like
salesDashboardMonthDropDown`中使用
and
无空格
我试过这个并且有效,
$(function(){
$("#salesDashboardYearDropDown, #salesDashboardMonthDropDown").on('change',function(){
var yearVal = $("#salesDashboardYearDropDown").val();
var monthVal = $('#salesDashboardMonthDropDown :selected').text();
var revenueLastYear = (monthVal + ' ' + (yearVal - 1).toString()).toString();
$('#Revenue').html(revenueLastYear);
});
});
同时检查您是否添加了jquery