【发布时间】:2016-04-19 14:29:50
【问题描述】:
我正在做一个程序,当它检测到 文本框 中的输入更改时,它需要做一些事情。但这对我不起作用。所以我改变我开始在控制台中给出值来验证它,每当它检测到输入发生变化时,它总是返回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>
【问题讨论】:
-
正如其他所说的滚动宽度在jQuery中没有包装,所以你可以用$(selector).prop('scrollWidth')来获得它。
标签: javascript jquery html