如何在 jQuery UI 滑块值更改时 运行 代码隐藏函数
How to run a Code Behind function when jQuery UI slider value changes
这是我的代码:
function display() {
$(document).ready(function () {
var txtStart = $("#TextBox1");
var txtStartDate = $(txtStart).val(); //Value from arrival
var txtEnd = $("#TextBox2");
var txtEndDate = $(txtEnd).val();
var minDate = new Date(txtStartDate);
var maxDate = new Date(txtEndDate);
$("#slider").slider({
min: minDate.getTime(),
max: maxDate.getTime(),
step: 60 * 60 * 24 * 1000, // 1 day
slide: function (e, ui) {
var currentDate = new Date(ui.value);
$('#now').text(currentDate.toDateString());
},
change: function (e, ui) {
/*I want to run the code behind function here*/
}
});
});
}
要执行 "code behind" 或您的服务器端脚本,您必须 Post 通过 AJAX 返回。在您的更改回调中,您需要执行以下操作:
change: function(e, ui){
$.ajax({
type: "POST",
url: "~/code_behind.aspx/Method",
data: { date: $('#now').val() },
contentType: "application/json; charset=utf-8"
});
}
由于您的 post 不清楚,我无法进一步澄清。您需要根据您的脚本和需要对其进行调整。
这是我的代码:
function display() {
$(document).ready(function () {
var txtStart = $("#TextBox1");
var txtStartDate = $(txtStart).val(); //Value from arrival
var txtEnd = $("#TextBox2");
var txtEndDate = $(txtEnd).val();
var minDate = new Date(txtStartDate);
var maxDate = new Date(txtEndDate);
$("#slider").slider({
min: minDate.getTime(),
max: maxDate.getTime(),
step: 60 * 60 * 24 * 1000, // 1 day
slide: function (e, ui) {
var currentDate = new Date(ui.value);
$('#now').text(currentDate.toDateString());
},
change: function (e, ui) {
/*I want to run the code behind function here*/
}
});
});
}
要执行 "code behind" 或您的服务器端脚本,您必须 Post 通过 AJAX 返回。在您的更改回调中,您需要执行以下操作:
change: function(e, ui){
$.ajax({
type: "POST",
url: "~/code_behind.aspx/Method",
data: { date: $('#now').val() },
contentType: "application/json; charset=utf-8"
});
}
由于您的 post 不清楚,我无法进一步澄清。您需要根据您的脚本和需要对其进行调整。