1.html结构
<div class="imagediv" >
<ul class="mui-table-view" style="padding-top: 5px;">
<li>
<img src="../images/iconfont-tianjia.png" class="imageup"
id="addnew" width="70px;" height="70px;">
</li>
</ul>
</div>
2.js部分
//图片上传开始
function plusReady(){
mui("body").on("tap",".imageup",function(){
page.imgUp();
})
}
var page=null;
page={
imgUp:function(){
var m=this;
plus.nativeUI.actionSheet(
{cancel:"取消",
buttons:[{title:"拍照"},
{title:"从相册选择"}]
}, function(e){//1 是拍照 2 从相册中选择
switch(e.index){
case 1:appendByCamera();break;
case 2:appendByGallery();break;
}
});
}
}
//拍照
function appendByCamera(){
plus.camera.getCamera().captureImage(function(e){
plus.io.resolveLocalFileSystemURL(e, function(entry) {
var path = entry.toLocalURL();//图片本地路径
var name=entry.name//图片名称
showImage(path,name)
}, function(e) {
mui.toast("读取拍照文件错误:" + e.message);
});
});
}
//从相册选择
function appendByGallery(){
plus.gallery.pick(function(path){
plus.io.resolveLocalFileSystemURL(path, function(entry) {
var name=entry.name
showImage(path,name)
}, function(e) {
plus.nativeUI.toast("读取拍照文件错误:" + e.message);
});
});
}
//图片显示说明:根据自己的业务逻辑来写,此处,我是需要图片的原来name和上传之后的name放到了隐藏域里,不需要的可以去掉
function show