网站首页 > 知识剖析 正文
单选框输入内容后,option中显示与之匹配的内容;
只是粗略写了一些,应用到实际场景中,需要做些相应的改变;
具体代码如下:
<html> <head> <style type="text/css"> #paymentType{ width: 200px; } #item{ display: none; width: 200px; max-height: 200px; overflow-y: scroll; overflow-x: hidden; } #item div{ width: 200px; height: 30px; background-color: #ddd; margin: 1px; text-align: left; padding-top: 5px; } #item div:hover{ background-color: #fff; cursor: pointer; } </style> <script type="text/javascript" src="http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js"></script> <script> var list = ["您好十大w", "您好打底","您好防辐射","您好二位","您好热是","您好哈哈哈","您好呵呵呵"] function changeValue{ var targetList = ; var html = ""; var value = $("#paymentType").val; for(var i = 0; i < list.length; i++){ if(list[i].toLowerCase.indexOf(value.toLowerCase) >= 0){ targetList.push(list[i]); html += "<div onclick='getValue(\"" + list[i] + "\")'>" + list[i] + "</div>"; } } document.getElementById('item').innerHTML = html; if(targetList.length > 0){ var height = targetList.length * 30; $("#item").height(height + "px") $("#item").show; }else{ $("#item").height("0px"); } } function getValue(value){ $("#paymentType").val(value); $("#item").hide; } function hide{ $("#item").hide; } function show{ $("#item").show; } </script> </head> <body> <div onmouseout="hide" onmouseover="show" style="width: 200px"> <input type="text" id="paymentType" name="paymentType" oninput ="changeValue" onfocus="changeValue"> <div id="item"></div> </div> </body> </html>
猜你喜欢
- 2024-11-10 详解jQuery(一) jqueryui
- 2024-11-10 web前端Jquery学习笔记一 jquery 前端
- 2024-11-10 jquery为表单控件传值并提交表单 jquery提交表单调用serialize方法
- 2024-11-10 jQuery基本操作 jquery基础
- 2024-11-10 利用jQuery实现简单的数据双向绑定
- 2024-11-10 jQuery基础教程学习笔记(五)事件的绑定和解绑
- 2024-11-10 jQuery中的事件——事件绑定、合成事件
- 2024-11-10 前端开发培训JQuery标准教案 前端开发教学
- 2024-11-10 JS类库Jquery(二):优雅的使用JQuery写Ajax实现前后端完美交互
- 2024-11-10 好程序员web前端教程分享Jquery常见面试题
- 最近发表
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)