我正在使用下面的代码来缩小字体大小,但它只会减少一次,我希望它在每次输入新字符时都减少。调整文本框的字体大小
<input type="text" value="" id="allocatedVisionBudget" onkeydown="resizetext()">
<style>
#allocatedVisionBudget {
width: 10%;
height: 93.3px;
background-color: rgba(255,255,255,0);
border: none;
font-size: 60px;
color: #7e8081;
padding: 0px;
}
</style>
<script>
function resizetext(){
var xy = document.getElementById('allocatedVisionBudget').value;
var x = document.getElementById("allocatedVisionBudget").style.fontSize=60;
//x;
xy;
var i=0;
var y=xy.length;
if(xy.length > 4) {
document.getElementById("allocatedVisionBudget").style.fontSize=x-20;
}
}
</script>
@SrinivasR,javascript,不是jquery! – Gavriel
@SrinivasR不,它不是。 'getElementById'只需要一个ID,所以你不会传递** hash **标识符。 – George
哦对不起我的坏.....我删除了我的答案。谢谢@Gavriel和乔治 –