我创建了一个数字键盘.按下数字键我想逐个改变'enterPin'DIV中'li span'元素的背景颜色.数字键的值将进入隐藏密码字段.什么应该是Jquery?
/* CSS is HERE/* .pin-list{ width:100%; float:left; text-align:center;} .pin-list li{ display:inline-block;} .pin-list li span{ width:15px; height:15px; display:inline-block; border:solid 1px #fff; border-radius:50%; margin:7px;} .keypad-container{ width:100%; float:left; margin:10px 0;} .keypad-container ul{ width:99%; display:inline-block; text-align:center;} .keypad-container ul li{ display:inline-block; margin:7px 10px;} .keypad-container ul li span{ width:60px; height:60px; display:inline-block; border-radius:50%; color:#fff; border:solid 1px #fff; text-align:center; line-height:60px; font-size:25px; cursor:pointer;} .keypad-container ul li span:hover, .keypad-container ul li span:active, .keypad-container ul li span:focus{ background:#fff; color:#000;}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 0
小智.. 6
添加您的HTML.
请提供以下js
$(document).on("click","#numberList li span",function(){ var js_password = $("#vPassword").val(); var enter_pin_length = js_password.length; if(enter_pin_length <= 3){ var eleObj = $("#enteredPin li span").get(enter_pin_length); $(eleObj).css('background',"red"); $("#vPassword").val(js_password + $(this).text()); } });
请在以下网址找到答案:https://jsfiddle.net/0pdL71m2/25/
添加您的HTML.
请提供以下js
$(document).on("click","#numberList li span",function(){ var js_password = $("#vPassword").val(); var enter_pin_length = js_password.length; if(enter_pin_length <= 3){ var eleObj = $("#enteredPin li span").get(enter_pin_length); $(eleObj).css('background',"red"); $("#vPassword").val(js_password + $(this).text()); } });
请在以下网址找到答案:https://jsfiddle.net/0pdL71m2/25/