一 字符长度5个字转换成省略号 js
写法
<body onload="city_length()">
<input type="text" readonly value="123456789" name="city-input" id="city-input"
class="city-input">
</body>
<script>
function city_length()
{
var str = document.getElementById("city-input").value;
var cd = str.length;
if(cd > 3){
document.getElementById("city-input").value = str.substring(0,5)+"...";
}
}
</script>
二 css 方式
input {
overflow: hidden
white-space: nowrap
text-overflow: ellipsis
}
网友评论