最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Return Confirm Call function if yes - Stack Overflow

programmeradmin1浏览0评论

Hi would like to call a function if the answer to return confirm is yes, just don't know where to put the myFunction(). my code is below.

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

Hi would like to call a function if the answer to return confirm is yes, just don't know where to put the myFunction(). my code is below.

<a href="#" onClick="return confirm('Are you sure your want to delete?')">Delete</a>
Share Improve this question asked Apr 28, 2017 at 5:35 KaoriYuiKaoriYui 9221 gold badge16 silver badges44 bronze badges
Add a ment  | 

6 Answers 6

Reset to default 2

Try it like,

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

Snippet,

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

try to wire the method call with &&

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

Use like this .Don't use the confirmation inline of the onlclick

  1. Declare the myfunction in onclick
  2. Then apply the confirmation inside the function

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

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

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

Use it like this

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

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

Use this

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

发布评论

评论列表(0)

  1. 暂无评论