首页javascriptwidthjQuery Style - 如何设置元素最大长度

jQuery Style - 如何设置元素最大长度

我们想知道如何设置元素最大长度。

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.4.4.min.js'></script>
<style type='text/css'>
.long {
  width: 100px;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $('input:text.long').attr('maxlength', parseInt($('input.long').css('width'), 10));
});
</script>
</head>
<body>
  <input type="text" class="long" />
</body>
</html>