📜  HTML | returnValue 事件属性

📅  最后修改于: 2021-11-09 09:17:13             🧑  作者: Mango

它可以设置检索一个布尔值,该值指示当前事件是否被取消。returnValue 事件属性指示此事件的默认操作是否已被阻止。该值默认设置为 true,它允许发生默认操作。
如果我们将默认值设置为 false,它将阻止默认操作。

句法:

event.returnValue = bool;
var booleanValue = event.returnValue;

返回值:
如果事件未被取消,则返回值为真,如果事件已被取消或默认值已被阻止,则返回值为假。

示例 1:此示例尝试取消 onclick 和 onchange 事件。



  

    returnValue event property
    
  

  

    
        

GeeksforGeeks

                        Try to check this checkbox.         
        
Select one of the one options.                  
        
           
    
  

输出:

示例2:与上一个示例类似,不同之处在于它不检查事件的可取消状态,它只是尝试取消onclick 和onchange 事件。



  

    returnValue event property
    
  

  

    

GeeksforGeeks

         In this it cancels the onclick event for the checkbox     
and the onchange event for the selection list below.     
The onclick event is cancelable, the onchange is not.     
    
        Try to check this checkbox.     
    
Select one of the one options.        

输出:

支持的浏览器:

  • 谷歌浏览器
  • IE
  • 边缘
  • 歌剧
  • 苹果Safari