第一版: 试图使用样式控制,在需要输入的时候把input输入框重叠在select控件之上。
IE下没有问题,结果ff下就杯具了,在firefox下selelct总是被放置最顶层。
<script>
$(document).ready(function(){
$("select").click(function(){
var thisId = $(this).attr('id');
var inputId = thisId.replace('addresses','input');
var spanId = thisId.replace('addresses','span');
$("#"+inputId).css({width:"100px",height:"20px",visibility:"visible"});
$("#"+spanId).css({position:"absolute",margin:"1px 1px 1px -6px"});
});
</script>
<input style="width:100px;height:20px;visibility:hidden;" id="input_LIR" onblur="this.value=this.value.toUpperCase();">
<span id="span_LIR">
<select id="addresses_LIR" style="margin-left:-102px;width:120px;" onchange= "document.all.input_LIR.value=this.value;">
<option value="SZXTZCZ" selected>SZXTZCZ</option>
</select>
</span>
第二版:通过事件或者按钮触发完成输入框和下拉框的切换
<style>
.div{width:180px; height:25px; float:left; clear:both; overflow:hidden;}
.input{width:100px;height:25px;display:none;}
.select{width:100px;height:25px;}
.editbtn{width:50px; height:25px;margin-bottom:0px;}</style>
<script>
var _edit = "Edit";
var _ok = "Ok";
$(document).ready(function(){
//绑定页面按钮点击事件
$("input[id^='btn_']").bind('click',function(){
var thisval = $(this).val();
var thisid = $(this).attr('id');
var selectId = thisid.replace('btn','addresses');
var inputId = thisid.replace('btn','input');
if(thisval == _edit){
$("#"+selectId).hide();
$("#"+inputId).show();
var selval = $("#"+selectId+" option:selected").val();
selval = selval ?selval : "";
$("#"+inputId).val(selval);
$(this).val(_ok);
}else{
$("#"+selectId).show();
$("#"+inputId).hide();
$(this).val(_edit);
$("#"+selectId+" option:selected").remove();
var inputval = $("#"+inputId).val();
$("#"+selectId).append("<option value='"+ inputval +"' selected>"+ inputval +"</option>");
}
});
//绑定所有输入框失去焦点事件
$("input[id^='input_']").bind('blur',function(){
var thisval = $(this).val();
var thisid = $(this).attr('id');
var selectId = thisid.replace('input','addresses');
var selval = $("#"+selectId+" option:selected").val();
if (selval == thisval || !new RegExp('^[a-zA-Z0-9]{7}$', '').test(thisval)) {
$("#"+selectId).show();
$(this).hide();
var btnId = thisid.replace('input','btn');
$("#"+btnId).val(_edit);
}else{
$(this).val(thisval.toUpperCase());
}
});
});
</script>
<table width="100%" border="0" cellpadding="3" cellspacing="1">
<tr class="tr1">
<td>Num </td>
<td>Message ID</td>
<td>Address</td>
<td>Send</td>
<td>Station Code</td>
</tr>
<tr>
<td>1</td>
<td>LDM</td>
<td>
<div class="div">
<input class="input" id="input_LDM">
<select id="addresses_LDM" class="select">
<option value="CANUFCZ" selected>CANUFCZ</option>
<option value="NNGTZ8X">NNGTZ8X</option>
<option value="NNGTF8X">NNGTF8X</option>
<option value="BJSTDCA">BJSTDCA</option>
</select>
<input type="button" id="btn_LDM" class="button" value="Edit" class="editbtn"/>
</div>
</td>
<td><input type="checkbox" name="selectMessageId" value="LDM" /></td>
<td><input type="text" disabled /></td>
</tr>
<tr>
<td>2</td>
<td>CPM</td>
<td>
<div class="div">
<input class="input" id="input_CPM">
<select id="addresses_CPM" class="select">
<option value="NNGTZ8X" selected>NNGTZ8X</option>
<option value="NNGTF8X">NNGTF8X</option>
<option value="NNGTZCZ">NNGTZCZ</option>
<option value="NNGTZCA">NNGTZCA</option>
</select>
<input type="button" id="btn_CPM" class="button" value="Edit" class="editbtn"/>
</div>
</td>
<td><input type="checkbox" name="selectMessageId" value="CPM" /></td>
<td><input type="text" disabled /></td>
</tr>
</table>
分享到:
相关推荐
Jquery可编辑下拉框控件,web开发非常实用,有多个功能设置
这是我在网上搜集的已经测试...实例实现了,Asp.net中应用Jquery FlexBox实现可输入,可选择的下拉框。而且可以自动从数据库中匹配数据,实现自能提示效果。 源码下载地址:http://bbs.wolefa.com/showtopic-134.html
jQuery Editable Select 是一个jQuery插件,它将选择转换成输入字段,其中根据输入的字符实时显示单个元素。当JavaScript不可用时,它就变成了一个真正的选择列表。
可以在http://www.cnblogs.com/strick/p/3884721.html查看到相关说明
JQuery可编辑表格、横向纵向菜单、标签页、级联下拉框、窗口
editableSelect可编辑搜索的下拉框插件
主要介绍了bootstrap可编辑下拉框jquery.editable-select的相关资料,需要的朋友可以参考下
SELECT_jQUERY下拉框...支持基本用法、宽度设置、下拉框分组、下拉框可编辑、下拉框联动、自定义列数、动态创建(修改)下拉框、恢复系统默认等功能。 本人在项目开发中的必备组件。 使用方法请详细阅读demo.html内容
特点: 构造初始化时,可传入一个SELECT对象控件,也可以传入DIV...另:压缩包中有两个PNG文件,是FIREWORK的编辑文件,大家可以用FIREWORK编辑下拉框右边的按钮外观,或者加入各种16*16大小的PNG小图标,用来装饰下拉框
本文给大家分享jQuery EasyUI编辑DataGrid用combobox实现多级联动效果的实例代码,代码简单易懂,非常不错,具有参考借鉴价值,感兴趣的朋友一起看看吧
可编辑的级联下拉列表框 漂亮的可编辑的下拉列表框 巧妙的方法实现了级联 jquery实现
jquery easy ui edatagrid 动态编辑表格 下拉框 联动 ,支持增加,编辑,删除行,日期狂,下拉框联动显示数据,测试ok
【写在前面的话】网站上很多用各种插件,比如依赖bootstrap... 基于这种原因,于是私下用jquery写了一个比较简单的多选下拉可填写组合框。 container{ margin: 20px auto; padding:0 15px; width: 50%; heigh
chosen_v1.2.0.zip chosen.jquery.js jQuery Chosen Plugin 是一个 jQuery 插件,用来将网页中的下拉框进行功能...可实现对下拉框的搜索,多个标签编辑等功能 下载地址:https://github.com/harvesthq/chosen/releases
站长必备jQuery可展开与折叠的竖向手风琴内容展示菜单 58.支持3级的jquery天蓝色动画菜单下载,适合艺术类、儿童类网站使用 5)对话框 1.jquery仿div透明模态弹出窗插件下载 2.jquery实现多风格消息弹出框插件...
例如“报告交付方式”包含固定交付时,第二个下拉框不可编辑,反之可以编辑,具体代码如下 报告交付方式: <select class="easyui-combobox" panelHeight="auto" style="width:195px" data-options="required:...
chosen源码 chosen-1.2.0.zip chosen.jquery.json jQuery Chosen Plugin 是一个 jQuery 插件,用来将网页中的...可实现对下拉框的搜索,多个标签编辑等功能 下载地址:https://github.com/harvesthq/chosen/releases
使用jQuery语法:$("#sel").val()或js语法:document.getElementById("sel").value均可得到所选值 要想获得选中的option的文本,使用$("#sel").attr("relText")获得relText属性值即可。 注意onchange函数中不...
NULL 博文链接:https://wenxianlong.iteye.com/blog/1995304