如果是,则返回确认呼叫功能

时间:2017-04-28 05:35:03

标签: javascript jquery html

如果返回确认的答案是肯定的,你想调用一个函数,只是不知道把myFunction放在哪里()。我的代码如下。

<a href="#" onClick="return confirm('Are you sure your want to delete?')">Delete</a>

6 个答案:

答案 0 :(得分:2)

尝试使用&&

连接方法调用
<a href="#" onClick="confirm('Are you sure your want to delete?') && myFunction() ">Delete</a>

答案 1 :(得分:1)

像这样使用。不要使用onlclick的内联确认

  1. 在onclick
  2. 中声明public static void main(String[] Args) throws IOException { ...... }
  3. 然后在功能
  4. 中应用确认

    &#13;
    &#13;
    myfunction
    &#13;
    function myfunction(){
    if(confirm('Are you sure your want to delete?')){
    //do stuff
    console.log('yes')
    }
    
    }
    &#13;
    &#13;
    &#13;

答案 2 :(得分:1)

试试吧,

<a href="#" onClick="myfunction()">Delete</a>

代码段,

&#13;
&#13;
<a href="#" 
  onClick="if(confirm('Are you sure your want to delete?')){alert('Delete');} else {alert('Dont delete')}">
 Delete</a>
&#13;
&#13;
&#13;

答案 3 :(得分:0)

像这样使用

<a href="#" onClick="confirmDelete()">Delete</a>

<script type="text/javascript">
function confirmDelete()
{
   if(confirm('Are you sure your want to delete?'))
   {
      /* Perform operations */
   }
}
</script>

答案 4 :(得分:0)

使用此

&#13;
&#13;
$(document).ready(function(){
   $("#myID").on("click",function(){
      if(confirm){
         alert('enter your code here');
      }
   });    
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" id="myID">Delete</a>
&#13;
&#13;
&#13;

答案 5 :(得分:0)

onClick="return confirm('Are you sure your want to delete?') && Yourfunction() "