js下拉框数据库
⑴ jsp 下拉框从数据库中如何取值
直接在页面前面连接数据库查询出结果result,然后下面就直接result里面取就可以了。
先声明(拿oracle举例):
<%!
String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
String DBURL = "jdbc:oracle:thin:@XXX.XXX.XXX.XXX:1521:XXX" ;
String DBUSER = "XXX" ;
String DBPASSWORD= "XXX" ;
Connection con = null ;
PreparedStatement pstmt = null ;
ResultSet rs = null ;
%>
执行查询:
<%
String sql = "select * from XXX" ;
try
{
Class.forName(DBDRIVER) ;
con = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
pstmt = con.prepareStatement(sql) ;
rs = pstmt.executeQuery() ;
%>
显示的时候如下:
<%
while(rs.next())
{
i++ ;
int id=rs.getInt("id");
String title = rs.getString("admin") ;
String author = rs.getString("user") ;
%>
<td><%=admin%></td>
<td><%=user%></td>
大概代码差不多这样了,你看着凑凑
⑵ 濡备綍鍦╓PS涓浣跨敤JS瀹炵幇涓嬫媺妗
鍦╓PS琛ㄦ牸涓锛屾偍鍙浠ラ氲繃浠ヤ笅姝ラょ紪鍐欎竴涓狫S瀹忔潵瀹炵幇杩欎釜闇姹傦细
棣栧厛锛屾偍闇瑕佷简瑙WPS琛ㄦ牸涓璊S瀹忕殑锘烘湰璇娉曞拰瑙勫垯銆俉PS琛ㄦ牸镄凧S瀹忓拰Excel镄刅BA瀹忔湁浜涚被浼硷纴浣嗘槸瀹冧滑鏄浣跨敤javaScript缂栧啓镄勚傛偍鍙浠ュ湪WPS琛ㄦ牸镄勫府锷╂枃妗d腑镓惧埌鐩稿叧镄勬暀绋嫔拰鍙傝冦
浠ヤ笅鏄涓涓澶ц嚧镄勬ラわ纴鍙浠ュ府锷╂偍寮濮嬬紪鍐栾繖涓瀹忥细
鍦ㄨ〃涓涓鍒涘缓涓涓浜嬩欢鐩戝惉鍣锛屼互渚垮湪鏁版嵁镟存敼镞惰Е鍙戝畯銆傛偍鍙浠ヤ娇鐢╓orksheet.onEdit鍑芥暟𨱒ュ仛鍒拌繖涓镣广备緥濡傦细
鍦ㄤ簨浠剁洃钖鍣ㄤ腑锛岀紪鍐欎唬镰佹潵妫镆ヨ〃涓涓镄勬暟鎹鏄钖﹀凡缁忓綍鍏ュ畬姣曘傚傛灉鏄锛屽垯瑙﹀彂瀵煎叆鏁版嵁镄勬搷浣溿傛偍鍙浠ヤ娇鐢≧ange.getValue鍑芥暟𨱒ヨ幏鍙栧崟鍏冩牸镄勫硷纴铹跺悗浣跨敤𨱒′欢璇鍙ユ潵妫镆ュ兼槸钖﹀瓨鍦ㄣ备緥濡傦细
鍦ㄥ煎叆鏁版嵁镄勬搷浣滀腑锛岀紪鍐欎唬镰佹潵灏呜〃涓涓镄勬暟鎹瀵煎叆鍒拌〃浜屼腑锛屽苟鎸夌収琛ㄤ簩镄勭増闱㈣嚜锷ㄥ悜涓嫔~鍏呮暟鎹銆傛偍鍙浠ヤ娇鐢≧ange.setValue鍑芥暟𨱒ヨ剧疆鍗曞厓镙肩殑鍊硷纴骞朵娇鐢ㄥ惊鐜璇鍙ユ潵阆嶅巻琛ㄤ竴涓镄勬暟鎹骞跺皢瀹冧滑濉鍏呭埌琛ㄤ簩涓銆备緥濡傦细
链钖庯纴鍦ㄤ簨浠剁洃钖鍣ㄤ腑锛岀紪鍐欎唬镰佹潵澶勭悊琛ㄤ竴涓鏁版嵁淇鏀圭殑𨱍呭喌銆傚傛灉鏁版嵁琚淇鏀癸纴闾d箞鎭ㄩ渶瑕佹洿鏂拌〃浜屼腑镄勬暟鎹浠ュ弽鏄犳渶缁埚笺傛偍鍙浠ヤ娇鐢≧ange.setValue鍑芥暟𨱒ヨ剧疆鍗曞厓镙肩殑鍊笺备緥濡傦细
javascript澶嶅埗浠g爜
Worksheet.onEdit(function(event) {
// 杩欓噷鍐欎綘镄勪唬镰
});
javascript澶嶅埗浠g爜
Worksheet.onEdit(function(event) {
var range = event.range;
var value = range.getValue();
if (value) {
// 鏁版嵁宸插綍鍏ワ纴瑙﹀彂瀵煎叆鏁版嵁镄勬搷浣
}
});
javascript澶嶅埗浠g爜
Worksheet.onEdit(function(event) {
var range = event.range;
var value = range.getValue();
if (value) {
// 鏁版嵁宸插綍鍏ワ纴瑙﹀彂瀵煎叆鏁版嵁镄勬搷浣
var sheet1 = workbook.getSheet("琛ㄤ竴");
var sheet2 = workbook.getSheet("琛ㄤ簩");
// 銮峰彇琛ㄤ竴涓镄勬暟鎹锛屽苟阆嶅巻瀹冧滑
var data = sheet1.getRange("A1:B10").getValues();
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < data[i].length; j++) {
// 灏嗘暟鎹濉鍏呭埌琛ㄤ簩涓锛屽苟镊锷ㄥ悜涓嫔~鍏
sheet2.getRange("A" + (i+1) + ":B" + (i+1)).setValues([data[i][j]]);
}
}
}
});
javascript澶嶅埗浠g爜
Worksheet.onEdit(function(event) {
var range = event.range;
var value = range.getValue();
if (value) {
// 鏁版嵁宸插綍鍏ワ纴瑙﹀彂瀵煎叆鏁版嵁镄勬搷浣
// ...锛堢渷鐣ュ煎叆鏁版嵁镄勪唬镰侊级...
} else {
// 鏁版嵁琚淇鏀癸纴镟存柊琛ㄤ簩涓镄勬暟鎹
var sheet1 = workbook.getSheet("琛ㄤ竴");
var sheet2 = workbook.getSheet("琛ㄤ簩");
// 銮峰彇琛ㄤ竴涓镄勬渶鏂版暟鎹锛屽苟镟存柊琛ㄤ簩涓镄勬暟鎹
var data = sheet1.getRange("A1:B10").getValues();
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < data[i].length; j++) {
// 镟存柊琛ㄤ簩涓镄勬暟鎹浠ュ弽鏄犳渶缁埚
sheet2.getRange("A" + (i+1) + ":B" + (i+1)).setValues([data[i][j]]);
}
}
}
});
⑶ 怎样用js实现数据库绑定到下拉框
需要先用ajax的方式获取数据库的记录 作为数组 然后 将数组内容加入的下拉框中作为选项
<head>
<metacharset="utf-8">
<title>无标题文档</title>
<scriptsrc="http://code.jquery.com/jquery-1.4.1.min.js"type="text/javascript"></script>
<script>
$(document).ready(funxtion{
vatlist1=$("#test");//获取list对象
$.get("demo_ajax_load.txt",function(result){//获取后台数据库记录
for(vari=0,len=result.row.length;i<result.row;i++){//result为返回的json对象row为包含选项的数组
varo=newOption(result.row[i].text,result.row[i].value);
list1.appendChild(o);
}
},"json");
})
</script>
</head>
<body>
<selectid="test">
<option>1</option>
</select>
</body>