使用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 (document.cookie.length > 0)
{
offset = document.cookie.indexOf (search)
if (offset != -1)
{
offset += search.length
end = document.cookie.indexOf ("", offset)
if (end == -1)
end = document.cookie.length
cookieValue = unescape (document.cookie.substring (offset, end))
}
}
return cookieValue
}
function writeCookie (name, value, hours)
{
var expire = ""
if (hours != null)
{
expire = new Date ((new Date ()).getTime () + hours * 3600000)
expire = " expires=" + expire.toGMTString ()
}
document.cookie = name + "=" + escape (value) + expire
}
writeCookie ("myCookie", "my name", 24)
alert (readCookie ("myCookie"))
</script>
</head>
<body>
</body>
</html>
你可以把文字和图片路径用一个特定的符号连接成一个字符串,再把这个字符串存到数据库字段中,比如用竖线符号:var str = 文字+"|"+图片路径
取出数据时再把它分割为两个数据:
var arr = 数据库返回的数据.split("|")
这时候 arr[0] 是文字,arr[1]是图片路径
JS获得的值 var name=document.getElenmentById("username").value
用url 提交到后台 脚本 winodw.open('addname.php?username='+name)
后台获取前台提交的数据后用mysql命令写入数据库
<?php$username= $_GET['username']
$link=mysql_connect('127.0.0.1','root','******') or die("connection error".mysql_error())
$flag=mysql_select_db("testdb",$link)
mysql_query("set names "."utf8")
mysql_query('insert into user ( username) value ('.$username.')')
?>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)