3 回答

TA貢獻(xiàn)1806條經(jīng)驗 獲得超8個贊
首先自定義一個ajax獲取要顯示在html頁面上的數(shù)據(jù)的方法,例如方法getdata,這個方法把獲取的返回值,通過js動態(tài)的顯示到html頁面要顯示的區(qū)域,然后再寫一個js定時器來實現(xiàn)實時調(diào)用數(shù)據(jù),
示例:
<script>
//定時器 異步運行
function hello(){
alert("hello");
}
var t2 = window.setTimeout("hello()",3000); //定時器
//window.clearTimeout(t2);//去掉定時器
</script>
把里面的hello方法換成你ajax獲取數(shù)據(jù)的方法名,然后改下定時器里面的方法名和時間,這里設(shè)置的是3秒鐘執(zhí)行一次可以設(shè)置成你自己要的數(shù)據(jù),就實現(xiàn)了你要的頁面實時調(diào)用數(shù)據(jù)了。

TA貢獻(xiàn)2036條經(jīng)驗 獲得超8個贊
其一:js動態(tài)生成的select,在生成時設(shè)置上select的name屬性,然后通過form表單提交,java后臺就能用request根據(jù)select的name屬性獲取。
其二:js動態(tài)生成的select,在生成時設(shè)置上select的id屬性,然后通過ajax異步提交的方式,java后臺就能用request根據(jù)select的name屬性獲取。
最后,你所謂的文本框中的值,不是這個select的所有option吧?如果是option的value,那就直接request.getParameter()獲取即可,如果想獲取<option value="a">b</option>中的b,那你需要記住其他辦法解決,這里不再贅述。

TA貢獻(xiàn)1848條經(jīng)驗 獲得超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(){ //獲取文本框?qū)ο?/p> var searchText = document.getElementById("searchText"); //獲取提交button對象 var action = document.getElementById("action"); //獲取要增加到的下拉列表對象 var selections = document.getElementById("selections"); //點擊提交的時候執(zhí)行的方法 action.onclick = function(){ //如果文本框?qū)ο笾兄挡粸榭?/p> if(searchText.value ){ //根據(jù)文本框中的值循環(huán)5次 for(var i =5;i>0;i--){ //設(shè)置下拉列表中的值的屬性 var option = document.createElement("option"); option.value = searchText.value + i; option.text= searchText.value+i; //將option增加到下拉列表中。 selections.options.add(option); } } } } //思路如上。你可以將點擊時將文本框中值傳到后臺,后臺返回數(shù)據(jù)后,在將數(shù)據(jù)存入下拉列表對象中。 </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> |
添加回答
舉報