这是一个非常简单的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div>if you input emoji(like:) into the input element below</div>
<div>you will be able to input only 4 emoji in chrome and firefox,the limited length is 8,it's ok</div>
<div>but when using safari,you can input 8 emoji,and got the length of 8,it's weird</div>
<input id='input' maxlength="8">
<script>
document.getElementById('input'),addEventListener('input',function(e){
console.log(e.target.value);
console.log(e.target.value.length);
})
</script>
</body>
</html>
&#13;
Safari浏览器可以输入8个表情符号(长度为16),所以我必须听取输入事件并特别是在safari中做子串以确保它与firefox和chrome一致,有没有其他方法可以实现这一点? / p>