我對jQuery和圖表非常陌生。這是我的腳本,它工作正常。它給了我用戶選擇的複選框的ID。我在我的控制器中有一個圖表操作,它也可以正常工作,但它會使用我所有的值創建圖表。我希望它根據腳本中選定的值創建圖表。我不知道如何將選定的值傳遞給我的控制器。從JavaScript MVC控制器傳遞數據
var checkboxes = $("input[type='checkbox']");
$(function()
{
function getValueUsingClass() {
/* declare an checkbox array */
var chkArray = [];
/* look for all checkboes that have a class 'chk' attached to it and check if it was checked */
$(".chk:checked").each(function() {
chkArray.push($(this).val());
});
/* we join the array separated by the comma */
var selected = chkArray.join(",") + ",";
/* check if there is selected checkboxes, by default the length is 1 as it contains one single comma */
if (selected.length > 1)
{
alert("You have selected " + selected);
}
else
{
alert("Please check at least one of the checkbox");
}
}
$("#Charter").click(function() {
getValueUsingClass();
});
});
您的操作方法未採用任何參數。你想發送什麼數據? – Shyju
我試圖發送arrar chkArray中的值到我的控制器中的我的Charter Action – lagfvu
迭代等Instaed,更簡單的是通過提取選中的複選框$('input [type =「checkbox」]:checked')。爲了溝通,您可以使用ajax並在您的控制器中返回JSON。然後在highcharts創建使用$ .getJSON()和加載數據/選項 –