我做了一些方案,其中只要檢測到的文本它需要做的事情的輸入變化。但它不適合我。所以我改變我開始給控制檯上的值來驗證它,只要它檢測到輸入變化,它總是返回undefined。 如何獲取用戶輸入的像素大小的文字?滾動寬度總是返回undefined
<!doctype html>
<html>
<head>
<style>
input[type=text] {
height: 20px;
width: 100px;
}
</style>
<script src="jquery.js"></script>
</head>
<body>
<input type="text" id="func"></input>
</body>
<script>
$("#func").change(function() {
console.log($("func").scrollWidth);
});
</script>
</html>
我需要輸入沒有全尺寸輸入框的像素的大小? –
沒有這樣的函數可用於獲取輸入字段內容的寬度。然而有一些approches這裏:http://stackoverflow.com/questions/3392493/adjust-width-of-input-field-to-its-input這裏:http://stackoverflow.com/questions/9328682/jquery -resizing形式輸入爲基礎的上值寬度 –