3
我的代碼不工作,我不明白爲什麼,我試圖能夠採取上傳的圖像,並使其成爲背景圖像,而不使用數據庫。請幫忙!我經常使用HTML和CSS,但是我嘗試了這裏列出的jQuery代碼來執行我正在尋找的任務。我想能夠採取上傳的圖像,並將其作爲背景圖片
代碼:
<html>
<head>
<title>Seamless Trial</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link class="jsbin" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script>
<style>
img {
padding:1px;
border:1px solid black;
background-color: white;
width:100px;
}
article, aside, figure, footer, header, hgroup, menu, nav, section { display: block; }
</style>
<script language="JavaScript">
<!--
// Copyright 2001 by www.CodeBelly.com Please do *not* remove this notice.
var backImage = new Array(); // don't change this
// Enter the image filenames you wish to use. Follow the pattern to use more images.
// The number in the brackets [] is the number you number in the brackets [] is the number you
// will use in the function call to pick each image.
// Note how backImage[0] = "" -- which would set the page to *no* background image.
backImage[0] = "#";
backImage[0].id = "blah";
backImage[1] = "#";
backImage[1].id = "blah";
backImage[2] = "black-rough-leather.jpg";
backImage[3] = "newspapers.jpg";
backImage[4] = "seamless-fuzzy-leopard.jpg";
// ----Do not edit below this line.---
function changeBGImage(whichImage){
if (document.body){
document.body.background = backImage[whichImage];}
}
//-->
<!-- input thingy
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah')
.attr('src', e.target.result)
.width(150)
.height(200);
};
reader.readAsDataURL(input.files[0]);
}
}
// end input thingy --!>
</script>
</head>
<body>
<input type='file' onchange="readURL(this);" /><br><br>
<a href="javascript:changeBGImage(1)"><img id="blah" src="#" alt="your image" /></a>
<a href="javascript:changeBGImage(2)"><img src="black-rough-leather.jpg"></a><br><br>
<a href="javascript:changeBGImage(3)"><img src="newspapers.jpg"></a><br><br>
<a href="javascript:changeBGImage(4)"><img src="seamless-fuzzy-leopard.jpg"></a><br><br>
<a href="javascript:changeBGImage(5)"><img src=""></a><br><br>
</body>
你在瀏覽器控制檯得到什麼錯誤? –
我並沒有明確指出錯誤,只是沒有做我想做的事情。 (我的意思是能夠將上傳的圖像製作成重複的背景圖像,或者自動上傳或上傳後點擊圖像。) – deganu