我正在尝试使用 __doPostBack 将一些数据从客户端传递到服务器端。我对 JS 不是很熟悉,但是在 Firebug 中调试时发生了一些奇怪的事情。我将首先显示我的代码。
<script type="text/javascript">
function BeginDownload() {
var temp = $("#waterwheel-carousel-horizon").CurrentSelectedImg().toString()
__doPostBack("ImgDownload", temp);
}
</script>
这是我试图调用的相关 jquery。
// Relevant Waterwheel jquery code.
$.fn.CurrentSelectedImg = function () {
return data.currentCenterItem.data().index; };
$.fn.waterwheelCarousel = function (options) {
// override the default options with user defined options
options = $.extend({}, $.fn.waterwheelCarousel.defaults, options || {});
return $(this).each(function () {
/* These are univeral values that are used throughout the plugin. Do not modify them
* unless you know what you're doing. Most of them feed off the options
* so most customization can be achieved by modifying the options values */
var data = {
itemsContainer: $(this).find(".carousel-images"),
totalItems: $(this).find(".carousel-images img").length,
containerWidth: $(this).width(),
containerHeight: $(this).height(),
currentCenterItem: null,
items: [],
itemDistances: [],
waveDistances: [],
itemWidths: [],
itemHeights: [],
itemOpacities: [],
carouselRotationsLeft: 0,
currentlyMoving: false,
itemsAnimating: 0,
currentSpeed: options.speed,
intervalTimer: null
};
// Setup the carousel
beforeLoaded();
// Preload the images. Once they are preloaded, the passed in function
// will be called and the carousel will be setup
preload(function () {
setupDistanceArrays();
setupCarousel();
setupStarterRotation();
});
还有幕后的代码。目前还没有达到。
// This code is currently not reached, but I put it here for completion.
#region EventTarget
private string EventTarget
{
get{
return Request.Form["__EVENTTARGET"].ToString().ToUpper();
}
}
#endregion EventTarget
#region HandlePostBack
void HandlePostBack()
{
switch (EventTarget)
{
case "ImgDownload":
DownloadImage(EventArgs);
break;
}
}
#endregion HandlePostBack
private void DownloadImage(string index)
{
string test = index;
}
最终发生的事情是我单击链接按钮,firebug 跳转到第一行代码,但在它完成该函数之前,它甚至在我传递变量之前突然跳转到 __doPostBack 函数的代码。为什么会这样?
我还应该提到我在 DNN 中这样做,如果这有影响的话。我认为问题可能是我形成该 jquery 函数的方式或我如何调用它。