「java搜索下拉」java实现搜索

博主:adminadmin 2022-11-23 13:20:08 81

今天给各位分享java搜索下拉的知识,其中也会对java实现搜索进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

在java中怎么通过下拉列表进行查询,再显示到页面上

你说的情况不够详细,如果你是希望这个select改变的时候去数据库查询相关数据的话,可以写javascript当select发生onchange时候提交表单(你的select应该是在一个form表单里吧),转到后台之后查询到相关数据再返回到这个页面,这时候就要加上 leilanhua 这位朋友说的代码,到前台后才能知道现在的数据时什么条件筛选的。

注意:你的option标签里不用写 id 属性 要写上value=“**”,这样到后台才知道你选的是什么。

java中怎么获取下拉框的值?

方法/步骤

首先我们先创建一个下拉框:

请点击输入图片描述

界面显示如下:

请点击输入图片描述

接下来我们用js来获取被选中的值:

请点击输入图片描述

首先我们通过selectedIndex来获得被选中的下标,再通过下标来获得值,界面结果如下:

请点击输入图片描述

当然,如果你是用jquery的话可以用下面的方法:

请点击输入图片描述

在java中,在下拉列表查询数据库的所有数据怎么查?

你的意思是先查询出来所有数据后,再显示到下拉菜单中去对吗?

如果是的话,按下面的思路做,相信你能做出来:

首先你访问这个界面前,要先去查询数据库中的数据,一般这些数据都装到一个list(集合,不一定用List)中去,然后再转到(如果是web项目,就是跳转了,这时把这个list装到request中,request.setAt....(“list”,lits);如果用的是桌面应用程序,就把这个list以参数的形式传到界面类上去)你的界面上,在界面上做一个下拦菜单,然后呢,就是一个循环输出list中包含的所有数据库中的数据,把每次循环取出来的信息放入下拉菜单的选项中去,这样,有多少数据,这个下拉菜单就有多少选项了,不知道是不是你想要的结果,如果不是,你可以再说详细点,方便大家为你解答,。

Java web根据下拉框选定内容进行查询数据怎么做?

Java web根据下拉框选定内容进行查询数据怎么做? 画面上下拉框的标签中,有onChange的JS方法,当下拉框的选定内容有变化时,会触发这个JS方法,在这个JS方法中,写与后台通信的交互,从后台取得需要的数据,然后表示出来。

用java编写随用户输入自动弹出下拉列表匹配项目,类似百度搜索

用ajax技术实现的具体例子如下

如下是实现的代码,大家有需要的可以看下:

script type="text/javascript"

var xmlHttp; //ajax初始化对象

var arrOptions = new Array(); //初始化数组元素

var currentValueSelected = -1;//表示当前选中的某项

//判断输入的字符是否超过5个

function querybylength(){

var woId = document.getElementById("woId").value;

if(woId.length=5){

//判断做什么动作

var intKey = -1;

if(window.event){

intKey = event.keyCode;

}

//alert(intKey);

if(intKey == 38){//按向上键

//alert(currentValueSelected);

if(currentValueSelected != -1){ //保证当前有用到SPAN

MoveHighlight(-1);

return false;

}

}else if(intKey == 40){ //按向下键

if(currentValueSelected != -1){ //保证当前有用到SPAN

MoveHighlight(1);

return false;

}

}else {

ajaxTest(woId); //初始化SPAN

}

}else {

HideTheBox();

currentValueSelected = -1;

}

}

//AJAX查询工单资料

function ajaxTest(name){

create();

if (xmlHttp==null){

alert ("您的浏览器不支持AJAX!");

return;

}

var url = "/spnewmes/servlet/QueryWOId?woId="+name;

xmlHttp.open("post",url,true);

xmlHttp.onreadystatechange = stateChanged;

xmlHttp.send(null);

}

function create(){

if (window.XMLHttpRequest) {

this.xmlHttp = new XMLHttpRequest();

}else if (window.ActiveXObject) {

this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

}

}

function stateChanged(){ //运行它进行ajax调用

if (xmlHttp.readyState==4){

var msg = xmlHttp.responseText; //获取返回值

arrOptions = msg.split(";");

//alert(arrOptions.length+":"+arrOptions);

if(arrOptions[0]!="")

Bulid(arrOptions); //给SPAN赋值

else

HideTheBox(); //隐藏SPAN

}

}

//创建并赋值span标签

function creatSpan(){

var elemSpan = document.createElement("span");//在页面创建span标签

elemSpan.id = "spanOutput";

elemSpan.className = "spanTextDropdown";

document.body.appendChild(elemSpan); //将上面创建的elemSpan元素加入到BODY的尾部

}

function Bulid(arrOptions){ //给SPAN赋值

var inner="";

SetElementPosition();//设置下拉框出现的位置

for(var i=0; i arrOptions.length; i++){

//alert(i+":"+arrOptions[i]);

inner+="span id=arr_"+i+" class='spanNormalElement' onmouseover='SetHighColor(this)' onclick='SetText()'font color=red"+arrOptions[i]+"/font/spanbr";

}

document.getElementById("spanOutput").innerHTML = inner;

if(inner!=""){

//alert('init');

document.getElementById("arr_0").className ="spanHighElement";//设置第一个顶为默认选中

currentValueSelected=0;

}

}

function SetElementPosition(){ //设置下拉框出现的位置

var selectedPosX = 0;

var selectedPosY = 0;

var theElement = document.form1.woId;

if (!theElement) return;

var theElemHeight = theElement.offsetHeight;

var theElemWidth = theElement.offsetWidth;

while(theElement != null){

selectedPosX += theElement.offsetLeft;

selectedPosY += theElement.offsetTop;

theElement = theElement.offsetParent;

}

xPosElement = document.getElementById("spanOutput");

xPosElement.style.left = selectedPosX;

xPosElement.style.width = theElemWidth;

xPosElement.style.top = selectedPosY + theElemHeight

xPosElement.style.display = "block";

}

function HideTheBox(){//隐藏下拉框

document.getElementById("spanOutput").style.display = "none";

currentValueSelected = -1;

}

function SetHighColor(theTextBox){//当鼠标划过变为选中状态

document.getElementById('arr_' + currentValueSelected).className ='spanNormalElement';

if(theTextBox){

currentValueSelected = theTextBox.id.slice(theTextBox.id.indexOf("_")+1, theTextBox.id.length);

}

//alert('SetHighColor:'+currentValueSelected);

document.getElementById('arr_'+currentValueSelected).className = 'spanHighElement';

}

function SetText(){//选中下拉框中的某个值

var theTextBox = document.form1.woId;

theTextBox.value = arrOptions[currentValueSelected];

document.getElementById("woId").value = theTextBox.value;

HideTheBox();

}

function MoveHighlight(xDir){//设置上下移动键

var currnum=parseInt(parseInt(currentValueSelected)+parseInt(xDir));

//alert('MoveHighlight:'+currentValueSelected+'+'+xDir+'='+currnum);

if(currnum = 0 currnumarrOptions.length ){

document.getElementById("arr_"+currentValueSelected).className ="spanNormalElement";

document.getElementById("arr_"+currnum).className ="spanHighElement";

currentValueSelected=currnum;

}else if(currnum==arrOptions.length){

document.getElementById("arr_"+currentValueSelected+"").className ="spanNormalElement";

currentValueSelected=0;

document.getElementById("arr_"+currentValueSelected+"").className ="spanHighElement";

}else if(currnum==-1){

document.getElementById("arr_"+currentValueSelected+"").className ="spanNormalElement";

currentValueSelected=arrOptions.length-1;

document.getElementById("arr_"+currentValueSelected+"").className ="spanHighElement";

}

}

/script

关于java搜索下拉和java实现搜索的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-23,除非注明,否则均为首码项目网原创文章,转载请注明出处。