为了账号安全,请及时绑定邮箱和手机立即绑定

JS调用后台数据查询,让查询到的数据在下拉列表里显示

JS调用后台数据查询,让查询到的数据在下拉列表里显示

暮色呼如 2019-05-25 15:15:50
JS调用后台数据查询,让查询到的数据在下拉列表里显示
查看完整描述

3 回答

?
慕森卡

TA贡献1806条经验 获得超8个赞

首先自定义一个ajax获取要显示在html页面上的数据的方法,例如方法getdata,这个方法把获取的返回值,通过js动态的显示到html页面要显示的区域,然后再写一个js定时器来实现实时调用数据,

示例:

<script> 


//定时器 异步运行

function hello(){

alert("hello");

}

var t2 = window.setTimeout("hello()",3000);   //定时器

//window.clearTimeout(t2);//去掉定时器

</script>

把里面的hello方法换成你ajax获取数据的方法名,然后改下定时器里面的方法名和时间,这里设置的是3秒钟执行一次可以设置成你自己要的数据,就实现了你要的页面实时调用数据了。




查看完整回答
反对 回复 2019-05-26
?
慕桂英3389331

TA贡献2036条经验 获得超8个赞


其一:js动态生成的select,在生成时设置上select的name属性,然后通过form表单提交,java后台就能用request根据select的name属性获取。
其二:js动态生成的select,在生成时设置上select的id属性,然后通过ajax异步提交的方式,java后台就能用request根据select的name属性获取。
最后,你所谓的文本框中的值,不是这个select的所有option吧?如果是option的value,那就直接request.getParameter()获取即可,如果想获取<option value="a">b</option>中的b,那你需要记住其他办法解决,这里不再赘述。



查看完整回答
反对 回复 2019-05-26
?
慕桂英546537

TA贡献1848条经验 获得超10个赞

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

/**

 * @author zhou2003737

 * @date  2014/09/25 16:39

 */

<html doctype="html">

    <head>

        <title></title>

        <script type="text/javascript">

                window.onload = function(){

                    //获取文本框对象

                    var searchText = document.getElementById("searchText");

                    //获取提交button对象

                    var action = document.getElementById("action");

                    //获取要增加到的下拉列表对象

                    var selections = document.getElementById("selections");

                    //点击提交的时候执行的方法

                    action.onclick = function(){

                        //如果文本框对象中值不为空

                        if(searchText.value ){

                            //根据文本框中的值循环5次

                            for(var i =5;i>0;i--){

                                //设置下拉列表中的值的属性

                                var option = document.createElement("option");

                                    option.value = searchText.value + i;

                                    option.text= searchText.value+i;

                                //将option增加到下拉列表中。

                                selections.options.add(option);

                            }

                        }

                    }

                }

            //思路如上。你可以将点击时将文本框中值传到后台,后台返回数据后,在将数据存入下拉列表对象中。

        </script>

    </head>

    <body>

        <p><input type="text" placeholder="请输入查询对象" autofocus  id="searchText"/></p>

        <p><input type="button" id="action" value="提交"/></p>

        <p><select id="selections">

 

        </select></p>

    </body>

</html>

 



查看完整回答
反对 回复 2019-05-26
  • 3 回答
  • 0 关注
  • 1673 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信