jsjquery上传图片的问题

jsjquery上传图片的问题,第1张

function showImage(fileid,imgid,atagID){

var ext = "_0"

var thumb = $('img#'+imgid)

var litbox = $('a#'+atagID)

var img1path = document.getElementById("img1path")

if($('.onTeedaError').length>0){

//img1path.value=""

}

var messages =document.getElementById("messages")

if(messages!=null){

//img1path.value=""

}

new AjaxUpload(fileid, {

action: '../../PdfChangeImgUploadServlet?pdfNameEnd=_PERT',

name: ext,

onSubmit: function(file, extension) {

extension=extension.toLowerCase()

if(extension=="pdf")

{

$("#photoError").hide()

$.blockUI({

message: $('span#displayBox'),

css: {

border: 'none',

width: '270px',

}

})

}else{

$("#photoError").show()

return false

}

},

onComplete: function(file, response) {

$('.pdfImg').remove()

$('#pfont').hide()

$.unblockUI()

var res = eval('('+response+')')

var timestemp = new Date().getTime()

var srcStr = res['srcStr']

$('#addImg').val(res['srcStr'])

var imgWidth = res['w'] + "px"

var imgHeight = res['h'] + "px"

$("#addImgWidth").val(imgWidth)

$("#addImgHeight").val(imgHeight)

var str = ""

var arr = []

arr = srcStr.split(",")

$('#imgFile').attr("value",srcStr)

for(var i=0i<arr.lengthi++){

var jpgsrc = arr[i] + '?'+ timestemp

if(i == 0){

str=str+"<a class=\"pdfImg\" style=\"margin-left:10px\" href="+jpgsrc+" rel=\"lightbox"+timestemp+"\">"

str=str+"<img class=\"jpgImgFont\" src="+jpgsrc+" style=\"vertical-align:middlecursor:pointerwidth:"+ imgWidth +"height:"+ imgHeight +" \" />"

str=str+"</a>"

} else {

str=str+"<a class=\"pdfImg\" style=\"margin-left:10pxdisplay:none\" href="+jpgsrc+" rel=\"lightbox"+timestemp+"\">"

str=str+"<img class=\"jpgImgFont\" src="+jpgsrc+" style=\"vertical-align:middlecursor:pointerwidth:"+ imgWidth +"height:"+ imgHeight +" \" />"

str=str+"</a>"

}

}

$('#imgFontDiv').append(str)

//thumb.attr('src', res['src']+'?'+timestemp)

//litbox.attr('href', res['src']+'?'+timestemp)

lightbox.refresh()

$('.jpgImgFont').attr('style', 'width: ' + imgWidth + 'height: ' + imgHeight + "" ).hide().fadeIn('slow')

if(res['img1path']!=""){

img1path.value=res['img1path']

}

if (imgid == 'imgFont') {

document.getElementById("photoName").value=res['srcStr'].substring(res['srcStr'].lastIndexOf("/")+1)

}

//}

}

})

}

function goClearPhoto(textID,imgID,hrefID,photoName){

var _file = document.getElementById(textID)

if(_file.files)

{

_file.value = ""

}

else

{

if (typeof _file != "object")

{

return null

}

var textID=document.getElementById(textID)

textID.value=""

var timestemp = new Date().getTime()

var src=document.getElementById("carPermitDefaultPath").value

var thumb = $('img#'+imgID)

var litbox = $('a#'+hrefID)

thumb.attr('src',"/groupware/images/PdfSample.png")

thumb.attr('style', 'width:230pxheight:240pxborder:0pxvertical-align:middlecursor:pointer' ).hide().fadeIn('slow')

litbox.attr('href',"/groupware/images/PdfSample.png"+'?'+timestemp)

$('.pdfImg').remove()

litbox.show()

lightbox.refresh()

var photoName=document.getElementById(photoName)

photoName.value=null

var imgFont= document.getElementById(imgFont)

imgFont.value = null

}

$("#imgFile").val("")

$("#img1path").val("")

}

html:

<body onload="showImage('insUpdPermitPhoto','imgFont','pfont')>

<div style="margin-top:3pxmargin-bottom:-8px">

<span class="sl-custom-file" style="">

<input type="text" id="img1path" placeholder="対応フォーマット:pdfのみ" readonly="true" class="input-height" style="width:260pxheight:20px"/>

<button class="btn btn-small" id="reference" type="button" style="margin-left:-2pxmargin-top:-12px">

<span style="color:black">参照</span>

</button>

<input type="file" id='insUpdPermitPhoto' class="fileTransIE10 ui-input-file" name="ufile" onChange="getValue(this,'img1path')" />

</span>

<a href="javascript:void(0)" onfocus="this.blur()" onClick="goClearPhoto('img1path','imgFont','pfont','photoName')" class="btn btn-small" style="margin-top:-15px">

<span style="color:black">削除</span>

</a>

</div>

后台用copy方法把图片复制到指定路径就可以了

1、新建一个HTML文件,保存为test.html,用于编写代码实现拖放功能 。

2、在test.html添加一个div标签,并且给它一个id,用于下面编写样式。

3、通过div的id , 给div定义CSS样式,例如,把div定义为一个带边框的长方形。下面将实现将图片拖放在这个长方形中。

4、在div的下面定义一张被拖放图片,并设置该图片的属性为允许被拖放。

5、在被拖放的图片上加上一个ondragstart事件,即图片被拖动时触发这个事件。再给事件一个函数,用于拖动图片时,把图片保存在一个变量中。

6、运行代码,在浏览器中查看结果:至此,完成了使用JS实现拖放图片到div中的功能。

使用背景属性

使用Background属性在Html文档中添加背景图片。按照以下步骤,我们可以轻松实现。

步骤1:我们在文本编辑器中键入HTML代码,或者用文本编辑器打开现有的HTML文件。

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>奔月教程(runoon.com)</title>

</head>

<body>

<h1>使用Background属性添加背景图片</h1>

</body>

</html>

步骤2:将光标移动到HTML文档中<body>的开始标签内,输入背景属性,如下所示:

<body background=" ">

步骤3:输入要添加的图片的路径,如果图片存储在与HTML文件同一目录中,请输入以下路径:

<body background="image.jpg">

如果我们的图像存储在任何其他目录中,则输入该图像的正确路径。如下所示:

<body background="/home/images/image.jpg">

如果我们的图片在互联网上,那么我们也可以使用URL添加图片,如下所示:

<body background="https://www.runoon.com/img/background7.jpg">

如果图像小于页面,图像会进行重复。

步骤4:最后,在文本编辑器中保存HTML文件或HTML代码。

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>奔月教程(runoon.com)</title>

</head>

<body background="/img/background7.jpg">

<h1>使用Background属性添加背景图片</h1>

</body>

</html>

效果展示:

图片

点击下方“阅读原文”可亲试效果

使用内部样式表

使用内部CSS在Html文档中添加背景图片,按照以下步骤可以轻松完成:

步骤1:我们在文本编辑器中输入HTML代码,或者用文本编辑器打开现有的HTML文件。

步骤2:在Html文档中的head标签内,定义<style>标签的开始和结束标签,如以下块所示:

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>奔月教程(runoon.com)</title></head>

<script>

//此处输入样式代码.........

</script>

<body>

<h1>使用CSS样式表添加背景图片</h1></body>

</html>

步骤3:在样式标签中输入元素代码,如以下所示,在<script>标签内输入background-image属性:

body { background-image:url('/img/background7.jpg')}

步骤4:最后,保存文本编辑器中的代码并运行该代码。执行后,我们可以看到html文档中指定的图像作为网页的背景。

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>奔月教程(runoon.com)</title></head>

<style>

body { background-image:url('/img/background7.jpg')}

</style>

<body>

<h1>使用CSS样式表添加背景图片</h1>

</body>

</html>

效果展示:


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11644513.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-17
下一篇2023-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存