在js里做入力项目长度检查,请问用jquery怎么获取文本框的Maxlength 。
3条回答 默认 最新
关注
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script> </head> <body> <input type="text" maxlength="200" id="demo"> <id id="txt"></id> </body> <script> let txt = document.getElementById("demo"); //js写法 js_text = txt.getAttribute("maxlength") // jquery 写法 jquery_text = $("#demo").attr('maxlength'); $("#txt").html("<br />js_text:" + js_text + "<br />"); $("#txt").append("jquery_text:" + jquery_text + "<br/>"); </script> </html>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用