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>