在达到最大字符限制时,我们有一个禁用的 div,需要在退格上启用。但是现在我们没有在 iPhone 中获得退格的 ASCII 码。我怎么能检测到 div 的退格键。这是我在 Query 中的字符限制代码,需要启用才能删除字符:
<script>
var charlimit = 20;
var maindiv = 'content';
var charlendiv = 'myDiv';
$().ready(function()
{
var div = document.getElementById (maindiv);
var text = $(div).text();
document.getElementById(charlendiv).innerHTML = charlimit - text.length;
$('#'+maindiv).keypress(function(e)
{
var div = document.getElementById (maindiv);
var text = $(div).text();
var code = e.keyCode || e.which;
if (text.length < charlimit)
{
div.contentEditable = true;
}
else
{
div.contentEditable = false;
if(code=='08' || code=='46' || code=='') //ASCII code not detect by keyboard back space
{
div.contentEditable = true;
}
}
});
$('#'+maindiv).keyup(function(e)
{
var code = e.keyCode || e.which;
var div = document.getElementById (maindiv);
var text = $(div).text();
document.getElementById(charlendiv).innerHTML = charlimit - text.length;
});
});
</script>