<table border="2px" rules="all"><tr><td><p>輸入密碼:<input type="password" onchange="changeText(this.value)" style="width:200px;" /></p></td><td></td></tr><tr><td><p>請確認密碼:<input type="text" style="width:185px;" id="text1" /></p></td><td></td></tr></table><script src="https://code.jquery.com/jquery-3.3.1.min.js"></script><script type="text/javascript">$(function(){function changeText(text){ //外面的onchange找不到這個函數,但去掉上面的$(function(){就找到了if(text.length < 9){$(':table tr:eq(0)').children('td:eq(1)').html('請輸入9位或以上的密碼').css("color",'red');}else{var text1 = document.getElementById('text1');text1.value = text;}}})</script>
為什么jq的$(function(){})把script里面函數包起來,外面的事件就找不到了呢?
麻辣土豆
2018-11-13 08:08:27