JS prevents users from submitting sample code multiple times

  • 2020-03-30 02:26:05
  • OfStack

 
<!doctype html> 
<html lang="en"> 
<head> 
<meta charset="UTF-8"> 
<title>Document</title> 
</head> 
<body> 
<input type="text" id="msg"> 
<a href="#" id="result"> submit </a> 
<div id="show"></div> 
<script src="jquery1.11.js"></script> 
<script> 
$(function(){ 
var flag = true; 
$("#result").on('click',function(){ 
if(flag){ 
flag = false; 
}else{ 
return; 
} 
$("#show").html('<p>'+$("#msg").val()+'</p>'); 

}); 
}) 
</script> 
</body> 
</html> 

so easy!

Related articles: