无法从asp.net代码中调用jquery函数
我是javascript/Jquery新手 我制作了一个javascript/Jquery小程序,用于向最终用户显示asp.net应用程序的反馈。类似于一个奇特的弹出窗口,根据消息的状态是“错误”、“警报”还是“成功”,它会滑入并具有不同的功能 (我知道这是以前做过的,有插件和其他东西可以做。我之所以不发布这篇文章,是因为我需要解决这个问题,我发布这篇文章是因为我需要了解我做错了什么,并了解如何正确调用我的js/jq函数。) 调用jq函数的asp.net codebehind方法使用RegisterClientScriptBlock();如果我只是将alert(“whatever”)放在;而不是调用弹出函数。如果我在文档外部准备了一个伪js函数,它也可以工作。但当我尝试调用弹出警报函数时,什么也没发生。它甚至没有进入函数内部 C# JAVASCRIPT无法从asp.net代码中调用jquery函数,jquery,asp.net,Jquery,Asp.net,我是javascript/Jquery新手 我制作了一个javascript/Jquery小程序,用于向最终用户显示asp.net应用程序的反馈。类似于一个奇特的弹出窗口,根据消息的状态是“错误”、“警报”还是“成功”,它会滑入并具有不同的功能 (我知道这是以前做过的,有插件和其他东西可以做。我之所以不发布这篇文章,是因为我需要解决这个问题,我发布这篇文章是因为我需要了解我做错了什么,并了解如何正确调用我的js/jq函数。) 调用jq函数的asp.net codebehind方法使用Regist
<script type="text/javascript">
/*
------------USER FEEDBACK POPUP-------------
---------Lautaro Arino @Viatel 2011---------
--------------------------------------------
*/
$(function () {
// ID of DIVS
var popUpId = "AlertPopUp";
var popUpCollapseId = "AlertCollapse";
var popUpDisbandId = "AlertDisband";
var titleId = "AlertTitle";
var messageId = "AlertMessage";
var bodyId = "AlertBody";
var headerId = "AlertHeader";
var imageId = "AlertImage";
// Get the div objects
var PopUpBox = $('#' + popUpId);
var CollapseDiv = $('#' + popUpCollapseId);
var DisbandDiv = $('#' + popUpDisbandId);
var TitleDiv = $("#" + titleId);
var MessageDiv = $("#" + messageId);
var Image = $('#' + imageId);
//Paths to error images
var successImagePath = "images/okej.jpg";
var alertImagePath = "images/alert.jpg";
var errorImagePath = "images/error.jpg";
var rootPathFromThisFile = "../../";
//parameters
var anmationSpeed = 300; //milliseconds. speed of the popup showing up, expanding and collapsing
var fadOutSpeed = 5000; //milliseconds. speed of success messages fading out
var popupWidth = PopUpBox.width();
var collapseWidth = DisbandDiv.width() + Image.width();
//EVENT HANDLERS
DisbandDiv.click(function () {
disbandPoPUp();
});
PopUpBox.click(function () {
if (state == "expanded") {
collapse();
} else if (state == "collapsed") {
expand();
}
});
//testbutton
$('#btnerror').click(function () {
AlertPopUp('Jättehemskt!', 'Oh nooo, an error is simulated!', 'error');
});
$('#btnalert').click(function () {
AlertPopUp('Glöm ej. ', 'Glöm ej att köpa mjölk', 'alert');
});
$('#btnsuccess').click(function () {
AlertPopUp('Woho!', 'Någonting har gått som det ska!', 'success');
});
//DISBAND
function disbandPoPUp() {
// alert("disbanding");
PopUpBox.stop();
PopUpBox.css('display', 'none');
state = "off";
};
//COLLAPSE
function collapse() {
// alert("collapsing");
PopUpBox.animate({ "right": -popupWidth + collapseWidth + 10 + "px" }, 300);
state = "collapsed";
};
//EXPAND
function expand() {
// alert("expanding");
PopUpBox.animate({ "right": "-5px" }, 300);
state = "expanded";
};
//AlertPopUp('Jättehemskt!', 'Oh nooo, an error is simulated!', 'error');
function AlertPopUp(title, message, type) {
// alert("function invoked");
//RESET POSITION
PopUpBox.css('right', -popupWidth + "px");
PopUpBox.css('opacity', '1.0');
PopUpBox.stop(); // in case there is an animation or fade going on
//SET MESSAGE
TitleDiv.text(title);
MessageDiv.text(message);
// SET POP UP TYPE AND DISPLAY
if (type == "success") {
// SUCESS
setBorderAndImage("green", successImagePath);
setFadeOut();
} else if (type == "alert") {
//ALERT
setBorderAndImage("orange", alertImagePath);
displayPopUpExpanded();
} else {
//ERROR
setBorderAndImage("red", errorImagePath);
displayPopUpExpanded();
}
//DISPLAY EXPANDED
function displayPopUpExpanded() {
PopUpBox.css('display', 'block');
expand();
}
//DISPLAY COLLAPSED
function displayPopUpCollapsed() {
PopUpBox.css('display', 'block');
collapse();
}
function setFadeOut() {
PopUpBox.css('display', 'block');
PopUpBox.animate({ "right": "-5px" }, anmationSpeed,
function () {
state = "expanded";
startFadeKill();
}
);
function startFadeKill() {
PopUpBox.fadeTo(fadOutSpeed, 1.0, function () {//this is just a delay before starting to fade out.
PopUpBox.fadeTo(fadOutSpeed, 0.0, function () {
// alert("fade done");
disbandPoPUp();
});
});
PopUpBox.mouseenter(function () {
//alert("mouse");
PopUpBox.stop();
PopUpBox.fadeTo("fast", 1.0);
});
}
}
//Set border color and image
function setBorderAndImage(color, imagePath) {
PopUpBox.css("border-color", color);
DisbandDiv.css("background-color", color);
//set image path
Image.attr("src", rootPathFromThisFile + imagePath);
}
};
})
</script>
/*
------------用户反馈弹出窗口-------------
---------Lautaro Arino@Viatel 2011---------
--------------------------------------------
*/
$(函数(){
//分区ID
var popUpId=“AlertPopUp”;
var popupclapseid=“警报崩溃”;
var popupdisband=“AlertDisband”;
var titleId=“AlertTitle”;
var messageId=“AlertMessage”;
var bodyId=“AlertBody”;
var headerId=“AlertHeader”;
var imageId=“AlertImage”;
//获取div对象
var popupox=$(“#”+popUpId);
var CollapseDiv=$(“#”+popupclapseid);
var DisbandDiv=$(“#”+POPUPDDISBANDID);
var TitleDiv=$(“#”+titleId);
var MessageDiv=$(“#”+messageId);
var Image=$('#'+imageId);
//错误图像的路径
var successImagePath=“images/okej.jpg”;
var alertImagePath=“images/alert.jpg”;
var errorImagePath=“images/error.jpg”;
var rootPathFromThisFile=“../../”;
//参数
var anmationSpeed=300;//毫秒。弹出窗口显示、展开和折叠的速度
var fadeOutspeed=5000;//毫秒。成功消息淡出的速度
var popupWidth=PopUpBox.width();
var collapseWidth=DisbandDiv.width()+Image.width();
//事件处理程序
DisbandDiv.单击(函数(){
解散popup();
});
popubox.click(函数(){
如果(状态==“扩展”){
塌陷();
}else if(状态==“已折叠”){
展开();
}
});
//测试按钮
$('#btn')。单击(函数(){
AlertPopUp('Jättehemskt!','Oh nooo,模拟了一个错误!','error');
});
$('#btnalert')。单击(函数(){
AlertPopUp(“Glöm ej.”、“Glöm ej att köpa mjölk”、“alert”);
});
$('#btnsucess')。单击(函数(){
警告弹出窗口(“Woho!”,“Någonting har gått som det ska!”,“success”);
});
//解散
函数disbandpoop(){
//警报(“解散”);
popubox.stop();
css('display','none');
state=“off”;
};
//崩溃
函数折叠(){
//警报(“崩溃”);
动画({“右”:-PopuWidth+CollapsWidth+10+“px”},300);
state=“崩溃”;
};
//扩展
函数展开(){
//警惕(“扩张”);
动画({“右”:“-5px”},300);
state=“扩展”;
};
//AlertPopUp('Jättehemskt!','Oh nooo,模拟了一个错误!','error');
功能警报弹出窗口(标题、消息、类型){
//警报(“调用的函数”);
//复位位置
css('right',-popuwWidth+“px”);
css('opacity','1.0');
popubox.stop();//如果正在进行动画或淡入淡出
//设置消息
标题四、正文(标题);
MessageDiv.text(消息);
//设置弹出式窗口类型和显示
如果(类型=“成功”){
//成功
setBorderAndImage(“绿色”,后续图像路径);
setFadeOut();
}else if(类型==“警报”){
//警觉的
setBorderAndImage(“橙色”,alertImagePath);
displayPopUpExpanded();
}否则{
//错误
setBorderAndImage(“红色”,errorImagePath);
displayPopUpExpanded();
}
//显示扩展
函数displayPopUpExpanded(){
css('display','block');
展开();
}
//显示已折叠
函数displaypopcollapsed(){
css('display','block');
塌陷();
}
函数setFadeOut(){
css('display','block');
动画({“右”:“-5px”},anmationSpeed,
函数(){
state=“扩展”;
startFadeKill();
}
);
函数startFadeKill(){
fadeTo(fadOutSpeed,1.0,function(){//这只是开始淡出之前的延迟。
fadeTo(FadeOutSpeed,0.0,函数(){
//警惕(“淡出完成”);
解散popup();
});
});
PopUpBox.mouseenter(函数(){
//警惕(“鼠标”);
popubox.stop();
PopUpBox.fadeTo(“快速”,1.0);
});
<script type="text/javascript">
/*
------------USER FEEDBACK POPUP-------------
---------Lautaro Arino @Viatel 2011---------
--------------------------------------------
*/
$(function () {
// ID of DIVS
var popUpId = "AlertPopUp";
var popUpCollapseId = "AlertCollapse";
var popUpDisbandId = "AlertDisband";
var titleId = "AlertTitle";
var messageId = "AlertMessage";
var bodyId = "AlertBody";
var headerId = "AlertHeader";
var imageId = "AlertImage";
// Get the div objects
var PopUpBox = $('#' + popUpId);
var CollapseDiv = $('#' + popUpCollapseId);
var DisbandDiv = $('#' + popUpDisbandId);
var TitleDiv = $("#" + titleId);
var MessageDiv = $("#" + messageId);
var Image = $('#' + imageId);
//Paths to error images
var successImagePath = "images/okej.jpg";
var alertImagePath = "images/alert.jpg";
var errorImagePath = "images/error.jpg";
var rootPathFromThisFile = "../../";
//parameters
var anmationSpeed = 300; //milliseconds. speed of the popup showing up, expanding and collapsing
var fadOutSpeed = 5000; //milliseconds. speed of success messages fading out
var popupWidth = PopUpBox.width();
var collapseWidth = DisbandDiv.width() + Image.width();
//EVENT HANDLERS
DisbandDiv.click(function () {
disbandPoPUp();
});
PopUpBox.click(function () {
if (state == "expanded") {
collapse();
} else if (state == "collapsed") {
expand();
}
});
//testbutton
$('#btnerror').click(function () {
AlertPopUp('Jättehemskt!', 'Oh nooo, an error is simulated!', 'error');
});
$('#btnalert').click(function () {
AlertPopUp('Glöm ej. ', 'Glöm ej att köpa mjölk', 'alert');
});
$('#btnsuccess').click(function () {
AlertPopUp('Woho!', 'Någonting har gått som det ska!', 'success');
});
//DISBAND
function disbandPoPUp() {
// alert("disbanding");
PopUpBox.stop();
PopUpBox.css('display', 'none');
state = "off";
};
//COLLAPSE
function collapse() {
// alert("collapsing");
PopUpBox.animate({ "right": -popupWidth + collapseWidth + 10 + "px" }, 300);
state = "collapsed";
};
//EXPAND
function expand() {
// alert("expanding");
PopUpBox.animate({ "right": "-5px" }, 300);
state = "expanded";
};
//AlertPopUp('Jättehemskt!', 'Oh nooo, an error is simulated!', 'error');
function AlertPopUp(title, message, type) {
// alert("function invoked");
//RESET POSITION
PopUpBox.css('right', -popupWidth + "px");
PopUpBox.css('opacity', '1.0');
PopUpBox.stop(); // in case there is an animation or fade going on
//SET MESSAGE
TitleDiv.text(title);
MessageDiv.text(message);
// SET POP UP TYPE AND DISPLAY
if (type == "success") {
// SUCESS
setBorderAndImage("green", successImagePath);
setFadeOut();
} else if (type == "alert") {
//ALERT
setBorderAndImage("orange", alertImagePath);
displayPopUpExpanded();
} else {
//ERROR
setBorderAndImage("red", errorImagePath);
displayPopUpExpanded();
}
//DISPLAY EXPANDED
function displayPopUpExpanded() {
PopUpBox.css('display', 'block');
expand();
}
//DISPLAY COLLAPSED
function displayPopUpCollapsed() {
PopUpBox.css('display', 'block');
collapse();
}
function setFadeOut() {
PopUpBox.css('display', 'block');
PopUpBox.animate({ "right": "-5px" }, anmationSpeed,
function () {
state = "expanded";
startFadeKill();
}
);
function startFadeKill() {
PopUpBox.fadeTo(fadOutSpeed, 1.0, function () {//this is just a delay before starting to fade out.
PopUpBox.fadeTo(fadOutSpeed, 0.0, function () {
// alert("fade done");
disbandPoPUp();
});
});
PopUpBox.mouseenter(function () {
//alert("mouse");
PopUpBox.stop();
PopUpBox.fadeTo("fast", 1.0);
});
}
}
//Set border color and image
function setBorderAndImage(color, imagePath) {
PopUpBox.css("border-color", color);
DisbandDiv.css("background-color", color);
//set image path
Image.attr("src", rootPathFromThisFile + imagePath);
}
};
})
</script>