将input输入的值传到后台,进行like查询
解决方案 »
- 程序老是报错:No getter method for property: "password2" of bean
- 快速高效取到数据库或数据文件中的数据
- 程序访问量大,服务器CPU一直增加
- FastJsp3.1 JSP开发框架正式开源,欢迎使用。
- servlet 问题 急!请各位高手指点迷津!
- 不用设置环境的问题?
- 来人啊啊啊啊啊
- 哪里有桌面版数据库(比如access或者别的数据库)的JDBC驱动程序下载?
- 紧急求救:EJB-QL支持嵌套吗?嵌套的SQL用EJB-QL怎么写呢,请大虾指点一二
- 实体bean之间的关系问题
- JSF加Liferay开发,如何设置上传文件大小限制的?
- struts2标签回显easyui datebox错误
结合ajax和jqueryui的autocomplete可以实现。数据就定义成json对象就可以了。参考一下我以前写的一小段:$("#searchInfo").autocomplete({
source: function( request, response ) {
var queryData = $("#searchInfo").val();
var byradio=$("input[name='byname']:checked").val();
var term = request.term;
if ( term in cache ) {
response( cache[ term ] );
return;
}
if(queryData.length < 1 )
return false ;
$.post("ajaxGetJsonStrByDrugname.gxz",{"ajax_drugname":queryData,"ajax_bytype":byradio},function(data){
if(data==""){
$("#sp_1").html("<font color='red'>对不起,没有该药品!</font>");
}else{
var $_dataObj = $.parseJSON(data);
cache[ term ] = $_dataObj;
response($_dataObj);
}
});
},
minLength: 1,
select: function( event, ui ) {
$( "#searchInfo" ).val(ui.item.value);
$.post("searchyp.gxz",{DrugId:ui.item.drugId},function(json){
var json1=$.parseJSON(json);
结合ajax和jqueryui的autocomplete可以实现。数据就定义成json对象就可以了。参考一下我以前写的一小段:$("#searchInfo").autocomplete({
source: function( request, response ) {
var queryData = $("#searchInfo").val();
var byradio=$("input[name='byname']:checked").val();
var term = request.term;
if ( term in cache ) {
response( cache[ term ] );
return;
}
if(queryData.length < 1 )
return false ;
$.post("ajaxGetJsonStrByDrugname.gxz",{"ajax_drugname":queryData,"ajax_bytype":byradio},function(data){
if(data==""){
$("#sp_1").html("<font color='red'>对不起,没有该药品!</font>");
}else{
var $_dataObj = $.parseJSON(data);
cache[ term ] = $_dataObj;
response($_dataObj);
}
});
},
minLength: 1,
select: function( event, ui ) {
$( "#searchInfo" ).val(ui.item.value);
$.post("searchyp.gxz",{DrugId:ui.item.drugId},function(json){
var json1=$.parseJSON(json);
我是新手 不会ajax这些 求指教
结合ajax和jqueryui的autocomplete可以实现。数据就定义成json对象就可以了。参考一下我以前写的一小段:$("#searchInfo").autocomplete({
source: function( request, response ) {
var queryData = $("#searchInfo").val();
var byradio=$("input[name='byname']:checked").val();
var term = request.term;
if ( term in cache ) {
response( cache[ term ] );
return;
}
if(queryData.length < 1 )
return false ;
$.post("ajaxGetJsonStrByDrugname.gxz",{"ajax_drugname":queryData,"ajax_bytype":byradio},function(data){
if(data==""){
$("#sp_1").html("<font color='red'>对不起,没有该药品!</font>");
}else{
var $_dataObj = $.parseJSON(data);
cache[ term ] = $_dataObj;
response($_dataObj);
}
});
},
minLength: 1,
select: function( event, ui ) {
$( "#searchInfo" ).val(ui.item.value);
$.post("searchyp.gxz",{DrugId:ui.item.drugId},function(json){
var json1=$.parseJSON(json);
是啊,我就是告诉LZ要在服务器做模糊查询,查好了再拿出来显示,哪有在前端做模糊查询的
结合ajax和jqueryui的autocomplete可以实现。数据就定义成json对象就可以了。参考一下我以前写的一小段:$("#searchInfo").autocomplete({
source: function( request, response ) {
var queryData = $("#searchInfo").val();
var byradio=$("input[name='byname']:checked").val();
var term = request.term;
if ( term in cache ) {
response( cache[ term ] );
return;
}
if(queryData.length < 1 )
return false ;
$.post("ajaxGetJsonStrByDrugname.gxz",{"ajax_drugname":queryData,"ajax_bytype":byradio},function(data){
if(data==""){
$("#sp_1").html("<font color='red'>对不起,没有该药品!</font>");
}else{
var $_dataObj = $.parseJSON(data);
cache[ term ] = $_dataObj;
response($_dataObj);
}
});
},
minLength: 1,
select: function( event, ui ) {
$( "#searchInfo" ).val(ui.item.value);
$.post("searchyp.gxz",{DrugId:ui.item.drugId},function(json){
var json1=$.parseJSON(json);
是啊,我就是告诉LZ要在服务器做模糊查询,查好了再拿出来显示,哪有在前端做模糊查询的
现在我是做个demo 现在列表有信息,如何实现输入j 得到结果JavaScript和jQuery
<html>
<style>
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.auto_hidden {
width:204px;border-top: 1px solid #333;
border-bottom: 1px solid #333;
border-left: 1px solid #333;
border-right: 1px solid #333;
position:absolute;
display:none;
}
.auto_show {
width:204px;
border-top: 1px solid #333;
border-bottom: 1px solid #333;
border-left: 1px solid #333;
border-right: 1px solid #333;
position:absolute;
z-index:9999; /* 设置对象的层叠顺序 */
display:block;
}
.auto_onmouseover{
color:#ffffff;
background-color:highlight;
width:100%;
}
.auto_onmouseout{
color:#000000;
width:100%;
background-color:#ffffff;
}
</style>
<script language="javascript">
<!--
/*
通用: 自动补全(仿百度搜索框)
作者:nj-troy
时间:2010-11-101
*/
var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
}
var Bind = function(object, fun) {
return function() {
return fun.apply(object, arguments);
}
}
function AutoComplete(obj,autoObj,arr){
this.obj=$(obj); //输入框
this.autoObj=$(autoObj);//DIV的根节点
this.value_arr=arr; //不要包含重复值
this.index=-1; //当前选中的DIV的索引
this.search_value=""; //保存当前搜索的字符
}
AutoComplete.prototype={
//初始化DIV的位置
init: function(){
this.autoObj.style.left = this.obj.offsetLeft + "px";
this.autoObj.style.top = this.obj.offsetTop + this.obj.offsetHeight + "px";
this.autoObj.style.width= this.obj.offsetWidth - 2 + "px";//减去边框的长度2px
},
//删除自动完成需要的所有DIV
deleteDIV: function(){
while(this.autoObj.hasChildNodes()){
this.autoObj.removeChild(this.autoObj.firstChild);
}
this.autoObj.className="auto_hidden";
},
//设置值
setValue: function(_this){
return function(){
_this.obj.value=this.seq;
_this.autoObj.className="auto_hidden";
}
},
//模拟鼠标移动至DIV时,DIV高亮
autoOnmouseover: function(_this,_div_index){
return function(){
_this.index=_div_index;
var length = _this.autoObj.children.length;
for(var j=0;j<length;j++){
if(j!=_this.index ){
_this.autoObj.childNodes[j].className='auto_onmouseout';
}else{
_this.autoObj.childNodes[j].className='auto_onmouseover';
}
}
}
},
//更改classname
changeClassname: function(length){
for(var i=0;i<length;i++){
if(i!=this.index ){
this.autoObj.childNodes[i].className='auto_onmouseout';
}else{
this.autoObj.childNodes[i].className='auto_onmouseover';
this.obj.value=this.autoObj.childNodes[i].seq;
}
}
}
,
//响应键盘
pressKey: function(event){
var length = this.autoObj.children.length;
//光标键"↓"
if(event.keyCode==40){
++this.index;
if(this.index>length){
this.index=0;
}else if(this.index==length){
this.obj.value=this.search_value;
}
this.changeClassname(length);
}
//光标键"↑"
else if(event.keyCode==38){
this.index--;
if(this.index<-1){
this.index=length - 1;
}else if(this.index==-1){
this.obj.value=this.search_value;
}
this.changeClassname(length);
}
//回车键
else if(event.keyCode==13){
this.autoObj.className="auto_hidden";
this.index=-1;
}else{
this.index=-1;
}
},
//程序入口
start: function(event){
if(event.keyCode!=13&&event.keyCode!=38&&event.keyCode!=40){
this.init();
this.deleteDIV();
this.search_value=this.obj.value;
var valueArr=this.value_arr;
valueArr.sort();
if(this.obj.value.replace(/(^\s*)|(\s*$)/g,'')==""){ return; }//值为空,退出
try{ var reg = new RegExp("(" + this.obj.value + ")","i");}
catch (e){ return; }
var div_index=0;//记录创建的DIV的索引
for(var i=0;i<valueArr.length;i++){
if(reg.test(valueArr[i])){
var div = document.createElement("div");
div.className="auto_onmouseout";
div.seq=valueArr[i];
div.onclick=this.setValue(this);
div.onmouseover=this.autoOnmouseover(this,div_index);
div.innerHTML=valueArr[i].replace(reg,"<strong>$1</strong>");//搜索到的字符粗体显示
this.autoObj.appendChild(div);
this.autoObj.className="auto_show";
div_index++;
}
}
}
this.pressKey(event);
window.onresize=Bind(this,function(){this.init();});
}
}
//-->
</SCRIPT>
<body>
<h1 align="center">自动完成函数(Autocomplete Function)</h1>
<div align="center"><input type="text" style="width:300px;height:20px;font-size:14pt;" id="o" onkeyup="autoComplete.start(event)"></div>
<div class="auto_hidden" id="auto"><!--自动完成 DIV--></div>
<script>
var autoComplete=new AutoComplete('o','auto',['b0','b12','b22','b3','b4','b5','b6','b7','b8','b2','abd','ab','acd','accd','b1','cd','ccd','cbcv','cxf']);
</SCRIPT>
</body>
</html>