使用dojo中的onclick事件刷新页面,我不想刷新页面

时间:2010-09-23 16:51:49

标签: javascript-events dojo javascript-framework

出于某些原因,在ie8中,当我在onclick事件后运行此函数时,它会导致页面刷新。我不想让页面刷新。

   var edealsButton = dojo.byId("edeals_button");
   var edealEmailInput = dojo.byId("edeals_email");
   var edealsSignup = dojo.byId("edeals_signup");
   var edealsThankYou = dojo.byId("edeals_thankyou");
   var currentValue = dojo.attr(edealEmailInput, 'value');
   if (currentValue != '' && currentValue != 'Enter your email') {
       var anim = dojox.fx.flip({
           node: edealsSignup,
           dir: "right",
           duration: 300
       })
       dojo.connect(anim, "onEnd", this, function() {
           edealsSignup.style.display = "none";
           edealsThankYou.style.display = "block";
       })
       dojo.connect(anim, "onBegin", this, function() {

           var criteria = { "emailAddress": '"' + currentValue + '"' };
           alert("currentValue " + currentValue);
           var d = essentials.CallWebserviceMethod('AlmondForms.asmx/SignupEdeal', criteria);
           d.addCallback(function(response) {
               var obj = dojo.fromJson(response);
               alert(obj.d);
               if (obj != null && obj.d != null) {
                   //alert(obj.d);
                   if (obj.d == false)
                   {
                       var edealSuccess = dojo.byId("edeals_succes_thankyou");
                       var edealError = dojo.byId("edeals_error_thankyou");

                       alert("edealError: " + edealError);
                       dojo.style(edealSuccess, "display", "none");
                       dojo.style(edealError, "display", "inline-block");
                   }
                   else
                   {
                       var edealSuccess = dojo.byId("edeals_succes_thankyou");
                       var edealError = dojo.byId("edeals_error_thankyou");

                       dojo.style(edealSuccess, "display","inline-block");
                       dojo.style(edealError, "display", "none");
                   }
               }
               else {
                   var edealSuccess = dojo.byId("edeals_succes_thankyou");
                   var edealError = dojo.byId("edeals_error_thankyou");

                   dojo.style(edealSuccess, "display", "none");
                   dojo.style(edealError, "display", "inline-block");
               }
           });
       })
       anim.play();
       edealEmailInput.innerHTML == 'Enter your email';
   } 
   else 
   {
       dojo.attr(edealEmailInput, 'value', 'Enter your email');
       dojo.style(edealEmailInput, 'color', '#CC2525');
   }

1 个答案:

答案 0 :(得分:1)

看起来您的“d.addCallback”代码可能无法正常处理。您可能想尝试在“anim.play();”之前放置“dojo.stopEvent()”。并查看是否会停止回发。

api.dojotoolkit.org站点,dojo.stopEvent()“阻止传播和clobbers传递事件的默认操作”。从docs.dojocampus.org站点,他们说“dojo.stopEvent(event)将阻止事件的任何传播(冒泡)的默认行为。”

祝你好运,希望这会帮助你解决一些问题。