这个很简单,给你举一个例子吧,首先在包含js的页面写一个:
<script
language='javascript'>
var
a='hello
word';//a
为要传送的值
windowlocationhref="xxx/argetphpinsert="+a;//target为任意一个目标文件用来接收这个变量a
</script>
然后你在targetphp文件中这样写:
<php
if(!empty($_GET['insert'])){
//
插入或者更新大数据库就可以了
}
>
--------------------------------------------------------
我建议你还是通过后台来处理,用JS的话,客户端压力太大,容易导致内存溢出,浏览器崩溃。
我用Java语言,通过jxl以及poi两种API给你写了例子,分别是用jxl读写excel文件,用poi读写excel文件。希望对你有帮助。(需要下载jxl和poi的jar包)
import javaioFileInputStream;
import javaioFileOutputStream;
import javaioIOException;
import javautilArrayList;
import javautilHashMap;
import javautilList;
import javautilMap;
import jxlCell;
import jxlSheet;
import jxlWorkbook;
import jxlformatColour;
import jxlformatUnderlineStyle;
import jxlwriteLabel;
import jxlwriteWritableCellFormat;
import jxlwriteWritableFont;
import jxlwriteWritableSheet;
import jxlwriteWritableWorkbook;
import orgapachepoihssfusermodelHSSFCell;
import orgapachepoihssfusermodelHSSFRichTextString;
import orgapachepoihssfusermodelHSSFRow;
import orgapachepoihssfusermodelHSSFSheet;
import orgapachepoihssfusermodelHSSFWorkbook;
import orgapachepoipoifsfilesystemPOIFSFileSystem;
public class ExcelUtil {
/
@param args
@throws IOException
/
public static void main(String[] args) throws IOException {
String outFile = "D:/workspace/JavaStudy/src/util/excel/testxls";
ExcelUtilwriteExcelByJXL(outFile, null);
}
/
@title: readExcelByJXL
@description: 通过jxl读取excel文件
@author yu ren tian
@email yurentian@163com
@param excelFile
@return
@throws IOException
/
private static List readExcelByJXL(String excelFile) throws IOException {
List rtn = new ArrayList();
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(excelFile);
Workbook excelWorkBook = WorkbookgetWorkbook(fileInputStream);
Sheet sheet = excelWorkBookgetSheet(0);
int m = sheetgetRows();
int n = sheetgetColumns();
for (int i = 1; i < m; i++) {
Map map = new HashMap();
for (int j = 0; j < n; j++) {
Cell cell = sheetgetCell(j, i);
String cellContent = cellgetContents();
switch (j) {
case 0:
mapput("studentName", cellContent);
break;
case 1:
mapput("Chinese", cellContent);
break;
case 2:
mapput("Math", cellContent);
break;
case 3:
mapput("English", cellContent);
break;
case 4:
mapput("assess", cellContent);
break;
}
}
rtnadd(map);
}
} catch (Exception e) {
eprintStackTrace();
} finally {
if (null != fileInputStream) {
fileInputStreamclose();
}
return rtn;
}
}
/
@title: writeExcelByJXL
@description: 通过jxl写入excel文件
@author yu ren tian
@email yurentian@163com
@param outFile
@param list
@throws IOException
/
private static void writeExcelByJXL(String outFile, List list)
throws IOException {
WritableWorkbook wwb;
FileOutputStream fos;
try {
fos = new FileOutputStream(outFile);
// wwb = WorkbookcreateWorkbook(file);
wwb = WorkbookcreateWorkbook(fos);
WritableSheet sheet = wwbcreateSheet("test", 0);
// 设置单元格的文字格式
WritableFont wf = new WritableFont(WritableFontARIAL, 12,
WritableFontNO_BOLD, false, UnderlineStyleNO_UNDERLINE,
ColourBLUE);
WritableCellFormat wcf = new WritableCellFormat(wf);
//wcfsetBackground(ColourGREEN);
wcfsetBackground(new CustomColor(11, "", 0, 0, 0));
for (int i = 0; i < 10; i++) {
Label label = new Label(i, 0, i + "", wcf);
sheetaddCell(label);
}
wwbwrite();
wwbclose();
fosclose();
} catch (Exception e) {
eprintStackTrace();
}
}
/
@title: readExcelByPOI
@description: 通过poi读取excel文件
@author yu ren tian
@email yurentian@163com
@param excelFile
@return
@throws IOException
/
private static List readExcelByPOI(String excelFile) throws IOException {
List rtn = new ArrayList();
FileInputStream fin = null;
try {
fin = new FileInputStream(excelFile);
POIFSFileSystem fs = new POIFSFileSystem(fin);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wbgetSheetAt(0);
int m = sheetgetLastRowNum() - sheetgetFirstRowNum() + 1;
int n = 5;
for (int i = 1; i < m; i++) {
Map map = new HashMap();
for (int j = 0; j < n; j++) {
HSSFCell cell = sheetgetRow(i)getCell((short) j);
int type = cellgetCellType();
String cellContentString = null;
double cellContentDouble = 0;
if (type == 1) {
cellContentString = cellgetRichStringCellValue()
getString();
Systemoutprintln("cellContentString="
+ cellContentString);
} else if (type == 0) {
cellContentDouble = cellgetNumericCellValue();
Systemoutprintln("cellContentDouble="
+ cellContentDouble);
}
Systemoutprintln("j=" + j);
switch (j) {
case 0:
mapput("studentName", cellContentString);
break;
case 1:
mapput("Chinese", new Double(cellContentDouble));
break;
case 2:
mapput("Math", new Double(cellContentDouble));
break;
case 3:
mapput("English", new Double(cellContentDouble));
break;
case 4:
mapput("assess", cellContentString);
break;
}
}
}
} catch (Exception e) {
eprintStackTrace();
} finally {
if (fin != null) {
finclose();
}
return rtn;
}
}
/
@title: writeExcelByPOI
@description: 通过poi写入excel
@author yu ren tian
@email yurentian@163com
@param outFile
@param list
@throws IOException
/
private static void writeExcelByPOI(String outFile, List list)
throws IOException {
FileOutputStream fos = new FileOutputStream(outFile);
HSSFWorkbook wb = new HSSFWorkbook();
for (int sheetCount = 0; sheetCount < 5; sheetCount++) {
HSSFSheet sheet = wbcreateSheet("组织" + (sheetCount + 1));
for (int rowCount = 0; rowCount < 10; rowCount++) {
for (int columnCount = 0; columnCount < 10; columnCount++) {
HSSFRow row = sheetcreateRow(rowCount);
HSSFCell cell = rowcreateCell(new Short(columnCount + ""));
HSSFRichTextString richTextString = new HSSFRichTextString(
"行=" + rowCount + " 列=" + columnCount);
cellsetCellValue(richTextString);
}
}
}
wbwrite(fos);
}
}
--------------------------------------------------------
使用cookie即可。
<!DOCTYPE HTML><html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="keywords" content="白菜编辑部">
<title>白菜编辑部</title>
<style type="text/css">
</style>
<script type="text/javascript">
function readCookie (name)
{
var cookieValue = "";
var search = name + "=";
if (documentcookielength > 0)
{
offset = documentcookieindexOf (search);
if (offset != -1)
{
offset += searchlength;
end = documentcookieindexOf (";", offset);
if (end == -1)
end = documentcookielength;
cookieValue = unescape (documentcookiesubstring (offset, end))
}
}
return cookieValue;
}
function writeCookie (name, value, hours)
{
var expire = "";
if (hours != null)
{
expire = new Date ((new Date ())getTime () + hours 3600000);
expire = "; expires=" + expiretoGMTString ();
}
documentcookie = name + "=" + escape (value) + expire;
}
writeCookie ("myCookie", "my name", 24);
alert (readCookie ("myCookie"));
</script>
</head>
<body>
</body>
</html>
NodeJS对mysql数据库的简单 *** 作
1
打开软件新建一个空的文件夹
2
然后引入mysql依赖 npm install mysql 1 完成后对应文件夹下会生成一个node_modules的文件夹,我们不需要去管它
3
编写mysqljs文件 // 导入mysql依赖constmysql=require("mysql")// 获取
这里面关联的全掏出来的话,够挑好机挑,只能简易描述一下可以:
setInterval或setTimeout这两个都可以实现,
setinterval为恒定运行时使用比较合适,如时间在跳,
setTimeout为条件满足时继续轮询比较合适,如升一级给下一个任务一样,
setTimeout("fun()",5000);5秒后执行fun()这个过程
function
fun(){
//这里要启动AJAX模型,向服务器发出GET或POST请求,
//如:接受为:userphp,PHP程序访问数据库进行处理
//返回responseText,JS可以调用,
//如果返回的结果你满意,允许继续轮询就启动setTimeout("fun()",5000);
//这样一来你就看到了一个自运行的一个机制了。。
//具体代码太多,无法展示。。。
}
以上就是关于要把js里的一个变量更新到数据库中,用PHP,这要怎么实现呢。全部的内容,包括:要把js里的一个变量更新到数据库中,用PHP,这要怎么实现呢。、js 将数据库查询出来的数据导入到excel中、原生js如何保存一个小数据到数据库里等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)