用于插入图像的 JavaScript

javascript to insert image

本文关键字:JavaScript 图像 插入 用于      更新时间:2023-09-26

我目前正在建立一个用于数字菜单显示的网站。我在获取提示用户更改页面图片的输入字段时遇到问题。图像将本地托管在显示器上网本上,而不是通过站点服务器(图片选择将定期更改)。任何想法都会有很大帮助 波纹管是我到目前为止的代码:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Custom Entree</title>
<style type="text/css">
body {
    overflow:hidden;
    }
#apIMG {
    position:absolute;
    top:50px;
    width:1080px;
    height:200px;
    z-index:2;
    text-align:right;
}
#apPDF {
    position:absolute;
    top:350px;
    width:100%;
    height:50%;
    z-index:1;
    text-align:center;
}
#pdfscoop {
    height:1358px;
    width:1050px;
}

#PRC {
    position:absolute;
    height:120px;
    width:100%;
    top:1708px;
    font-family:BrushScriptStd;
    text-align:center;
    }
#price {
    height:120px;
    width:1080px;
    text-align:center;
    font-family:BrushScriptStd;
    font-size:110px;
    color:#090;
    }
</style>
<script type="text/javascript">
var img = document.getElementById('logo').src='';
document.images.item(
</script>

</head>
<body>
<div id="apIMG"><a href="http://www.artisancateringandevents.com/Content_Pages/scoop_webMenu.html" target="_top"><img src="scoopTitle.png" height="130%" width="*" ></image></a></div>
<div id="apPDF">
<embed name="" id="logo" src="custom.pdf#scrollbar=0" type="application/pdf" width="900px" height="900px" scrollbar="0" /><input name="" type="image" width="900" height="900" /></div>
<div id="PRC"><input type="text" id="price" border="0" /><br/>
<input type="text" id="price" border="0" /></div>
</body>
</html>

你的问题似乎不是那么清楚。 要替换图像的来源,方法很简单:

var images = ['imageone.jpg','imagetwo.jpg'];    
var img    = document.getElementById('logo');
img.src    = images[0];

[编辑:] 根据您使用 file://的最后评论,看起来这就是您所追求的:

<script type='text/javascript'>
    function callme() {
        document.getElementById('logo').src = document.getElementById('file').value;
    }
</script>
<img id='logo' src='' />
<input id='file' type='file' onchange='callme()' value='' />