How to determine the length of the actual characters entered in the input tag input box in HTML

There is no way to directly obtain the length of the input content in html.

It is generally recommended that you use JS to coordinate calculations


<input type="text" id="username" onpropertychange="getlen()">
<input type="text" id="lennum" value="0">
<script>
function getlen(){
 document.getElementById('lennum').value=document.getElementById('username').value.length;
}
</script>

Effect:,

2 answers

#Collection# Is it cheaper to buy air tickets as early as possible?

wanyanjiabin
2017-06-04 · Know the partner software expert

focus on

There is no way to directly obtain the length of the input content in html.

It is generally recommended that you use JS to coordinate calculations

1

2

3

4

5

6

7

<input type="text" id="username" onpropertychange="getlen()">

<input type="text" id="lennum" value="0">

<script>

function getlen(){

 document.getElementById('lennum').value=document.getElementById('username').value.length;

}

</script>

Effect:

Note that the onpropertychange event used here only supports IE browser. You can also use the event oninput that comes with HTML5. However, oninput only supports Browsers that support HTML5 are invalid below IE9.

 

Guess you like

Origin blog.csdn.net/tianxianghuiwei/article/details/134093806