---
title: "js控制Backspace 回退 "
author: "可怜的猫"
date: "2015-12-18T14:13:00Z"
tags: []
categories: ["Web前端"]
slug: "js-backspace"
draft: false
lastmod: "2015-12-18T14:13:00Z"
id: 2265006
url: "https://lafecat.iteye.com/blog/2265006"
---

//控制backspace  
$(document).keydown( function(e)  
        {  
    //获取键盘的按键CODE  
    var k=e.keyCode;  
    if(k == 8){  
        //获取操作的标签对象  
        var act = document.activeElement.tagName.toLowerCase();  
        //如果按键为“backspace”并且标签对象为body或html时，返回false  
        if(act.indexOf("body") != -1 || act.indexOf("html") != -1)  
        {  
           return false;  
        }  
        return true;  
    }  
    return true;  
});