一 字符長(zhǎng)度5個(gè)字轉(zhuǎn)換成省略號(hào) 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
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者