服务器端事件不会与jQuery一起被激活 [英] Server Side Event Is Not Firing With jQuery
本文介绍了服务器端事件不会与jQuery一起被激活的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在网上购物添加到购物车创建飞到篮子,对于飞到篮子我使用一个jQuery。下面提到......
< script type = 文本/ JavaScript的跨度>>
$( document )。ready( function (){
$(< span class =code-string>' 。addProduct')。each( function (){
var img = $( #ctl00_ContentPlaceHolder1_imgProduct);
$( this )。click( function (){
flyToElement($(img),$(' #ctl00_lbtnMyCart')) ;
返回 false ;
});
});
$(' 。removeProduct')。each( function (){
var img = $( this )。nearest(' li')。find(' IMG:第一'跨度>);
$( this )。click( function (){
flyFromElement($ (img),$(' #basket'));
return false ;
});
});
});
function flyToElement(flyer,flyingTo,callBack / * 回调是可选的* / ){
var $ func = $(此跨度>);
var divider = 3 ;
var flyerClone = $(flyer).clone();
$(flyerClone).css({
position:' 绝对',
top:$(flyer).offset()。top + px,
left:$(flyer).offset()。left + px,
opacity: 1 ,
' z -index': 1000
});
$(' body')。append($(flyerClone));
var gotoX = $(flyingTo).offset()。left +($(flyingTo).width()/ 2 ) - ($(flyer).width()/ divider)/ 2;
var gotoY = $(flyingTo).offset()。top +($(flyingTo).height()/ 2 ) - ($(传单).height()/ divider)/ 2;
$(flyerClone).animate({
opacity: 0 。 4 ,
左:gotoX,
top:gotoY,
width:$(flyer).width()/ divider,
height:$(flyer).height( )/ divider
}, 700 ,
function (){
$(flyingTo).fadeOut(' fast',函数(){
$(flyingTo).fadeIn(' fast' , function (){
$(flyerClone).fadeOut(' fast', function (){
$(flyerClone).remove();
if (callBack!= null ){
callBack.apply($ func);
}
});
});
});
});
}
功能 flyFromElement(flyer,flyingTo,callBack / * 回调是可选的* / ){
var $ func = $(此跨度>);
var divider = 3 ;
var beginAtX = $(flyingTo).offset()。left +($(flyingTo).width()/ 2 ) - ($(flyer).width()/ divider)/ 2;
var beginAtY = $(flyingTo).offset()。top +($(flyingTo).width()/ 2 ) - ($(传单).height()/ divider)/ 2;
var gotoX = $(flyer).offset()。left;
var gotoY = $(flyer).offset()。top;
var flyerClone = $(flyer).clone();
$(flyerClone).css({
position:' absolute',
top:beginAtY + px,
left: beginAtX + px,
opacity: 0 。 4 ,
' z-index': 1000 ,
宽度:$(传单).width()/ divider,
height:$ (传单).height()/ divider
});
$(' body')。append($(flyerClone));
$(flyerClone).animate({
opacity: 1 ,
left:gotoX,
顶部:gotoY,
宽度:$(传单).width(),
高度:$(传单).height()
}, 700 ,
function (){
$(flyerClone).remove();
$(flyer).fadeOut (' fast', function () {
$(flyer).fadeIn(' fast', function (){
if (callBack!= null ){
callBack.apply($ func);
}
});
});
});
}
< / script>
我的加入购物车div是
< a href = # class = addProduct >
< asp:ImageButton ID = ibtnAddToCart runat = server OnClick = ibtnAddToCart_Click
ImageUrl = 〜/ images / add-to-cart.gif / > < / a >
我有onclick事件
protected void ibtnAddToCart_Click( object sender,ImageClickEventArgs e)
{
this .addCart();
}
飞到篮筐正在运作,但是事件没有解雇,如果有任何解决方案适用于这种情况..
请帮帮我..
解决方案
( document )。ready(< span class =code-keyword> function (){
(' 。addProduct')。each( function (){
var img =
( #ctl00_ContentPlaceHolder1_imgProduct);
I am creating fly to basket on Online Shopping "Add To Cart", For flying to basket i am using one jQuery. Below mentioning...
<script type="text/javascript">
$(document).ready( function(){
$('.addProduct').each(function(){
var img = $("#ctl00_ContentPlaceHolder1_imgProduct");
$(this).click(function(){
flyToElement($(img), $('#ctl00_lbtnMyCart'));
return false;
});
});
$('.removeProduct').each(function(){
var img = $(this).closest('li').find('img:first');
$(this).click(function(){
flyFromElement($(img), $('#basket'));
return false;
});
});
});
function flyToElement(flyer, flyingTo, callBack /*callback is optional*/) {
var $func = $(this);
var divider = 3;
var flyerClone = $(flyer).clone();
$(flyerClone).css({
position: 'absolute',
top: $(flyer).offset().top + "px",
left: $(flyer).offset().left + "px",
opacity: 1,
'z-index': 1000
});
$('body').append($(flyerClone));
var gotoX = $(flyingTo).offset().left + ($(flyingTo).width() / 2) - ($(flyer).width()/divider)/2;
var gotoY = $(flyingTo).offset().top + ($(flyingTo).height() / 2) - ($(flyer).height()/divider)/2;
$(flyerClone).animate({
opacity: 0.4,
left: gotoX,
top: gotoY,
width: $(flyer).width()/divider,
height: $(flyer).height()/divider
}, 700,
function () {
$(flyingTo).fadeOut('fast', function () {
$(flyingTo).fadeIn('fast', function () {
$(flyerClone).fadeOut('fast', function () {
$(flyerClone).remove();
if( callBack != null ) {
callBack.apply($func);
}
});
});
});
});
}
function flyFromElement(flyer, flyingTo, callBack /*callback is optional*/) {
var $func = $(this);
var divider = 3;
var beginAtX = $(flyingTo).offset().left + ($(flyingTo).width() / 2) - ($(flyer).width()/divider)/2;
var beginAtY = $(flyingTo).offset().top + ($(flyingTo).width() / 2) - ($(flyer).height()/divider)/2;
var gotoX = $(flyer).offset().left;
var gotoY = $(flyer).offset().top;
var flyerClone = $(flyer).clone();
$(flyerClone).css({
position: 'absolute',
top: beginAtY + "px",
left: beginAtX + "px",
opacity: 0.4,
'z-index': 1000,
width:$(flyer).width()/divider,
height:$(flyer).height()/divider
});
$('body').append($(flyerClone));
$(flyerClone).animate({
opacity: 1,
left: gotoX,
top: gotoY,
width: $(flyer).width(),
height: $(flyer).height()
}, 700,
function () {
$(flyerClone).remove();
$(flyer).fadeOut('fast', function () {
$(flyer).fadeIn('fast', function () {
if (callBack != null) {
callBack.apply($func);
}
});
});
});
}
</script>
My Add to Cart div is
<a href="#" class="addProduct">
<asp:ImageButton ID="ibtnAddToCart" runat="server" OnClick="ibtnAddToCart_Click"
ImageUrl="~/images/add-to-cart.gif" /></a>
I have onclick event
protected void ibtnAddToCart_Click(object sender, ImageClickEventArgs e)
{
this.addCart();
}
Flying to basket is working, But Event is not firing , If any have solution for this situation..
Please help me..
解决方案
(document).ready( function(){
('.addProduct').each(function(){ var img =
("#ctl00_ContentPlaceHolder1_imgProduct");
这篇关于服务器端事件不会与jQuery一起被激活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文