2012-04-27 66 views
0

这是我与嵌入式JS使用Javascript - 如何停止执行

<a style="padding: 5px;" onclick="confirm_message(); $('contact_693_').show(); $('errors_693_').hide(); this.hide(); $('dont_693_').show();; return false;" id="the_link_693_" href="#" class="add_someone_else">Check it out</a> 

这里是我的功能

function confirm_message(){ 
     var response = confirm("Are you sure?"); 
    if(response){ 
     return false; 
    }else{ 
      return false; 
     } 
} 

基本上我不希望任何其他JS的火,如果链接用户点击确认中没有....但所有其他javascript

$('contact_693_').show(); $('errors_693_').hide(); this.hide(); $('dont_693_').show();; return false;" 

仍会触发用户是否单击是或否确认......就如何解决这一问题的任何想法....

而且此嵌入式JS不是由我创建,是建立与红宝石在页面上...

+0

你能后产生这个Ruby代码?它是Rails吗? – andrewdotnich 2012-04-27 01:49:29

+0

是的......一秒.. – Trace 2012-04-27 01:53:27

回答

3

抛出一个错误,这样:

function confirm_message(){ 
    var response = confirm("Are you sure?"); 
    if(response){ 
     return false; 
    }else{ 
     throw new Error("Chuck Norris roundhouse kicked your JS, sorry."); // or something a little more descriptive 
    } 
} 

这不是很漂亮,但它应该停止所有未来的JS处理。

+0

怎么会抛出一个错误帮助用户....我只是想关闭盒子和其他js不能射击。 – Trace 2012-04-27 01:56:51

+2

@Matt:抛出一个错误会导致页面上的所有其他Javascript停止执行。这包括'其他js'。 – 2012-04-27 01:57:41

+0

啊......没想到......谢谢 – Trace 2012-04-27 02:03:00

2

包括在确认功能代码:

function confirm_then_execute(){  
    var response = confirm("Are you sure?");  
    if(response){ 
     $('contact_693_').show(); $('errors_693_').hide();this.hide(); $('dont_693_').show();return false;" 
    } 
    else{  
     return false;  
    } 
} 

HTML:

<a style="padding: 5px;" onclick="confirm_then_execute()" id="the_link_693_" href="#" class="add_someone_else">Check it out</a>     
+0

我不能这样做,因为我没有那些div id和class在js level – Trace 2012-04-27 01:55:29

+0

如何将id作为参数传递:confirm_then_execute(id1,id2)? – Christophe 2012-04-27 02:01:26

+0

这可能是一个干净的方式 – Trace 2012-04-27 02:03:15