var pictureSource; //图片来源
var destinationType; //设置返回值的格式
// var imageURI;
document.addEventListener("deviceready",onDeviceReady,false);// 等待PhoneGap连接设备

// PhoneGap准备就绪,可以使用!
 function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
   function onPhotoURISuccess(imageURI) {

// 取消注释以查看图片文件的URI
// console.log(imageURI);
// 获取图片句柄
var largeImage = document.getElementById('largeImage');
 
// 取消隐藏的图像元素
largeImage.style.display = 'block';

// 显示拍摄的照片
// 使用内嵌CSS规则来缩放图片
largeImage.src = imageURI;
} function uploadphoto(imageURI)  { 
        var options = new FileUploadOptions(); 
        options.fileKey="image"; 
        options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1); 
        options.mimeType="image/jpeg"; 

        var params = new Object(); 
        params.value1 = "jpeg"; 
    //  params.value2 = "param";   
 
        options.params = params;   
 
        var ft = new FileTransfer(); 
        ft.upload(imageURI, "http://192.168.1.200/xinshi/upload_image.php", win, fail, options); 
    }
   onFail:function (mesage) {
alert('Failed because: ' + message);
   },
    function win(r) { 
        console.log("Code = " + r.responseCode); 
        console.log("Response = " + r.response); 
        console.log("Sent = " + r.bytesSent); 
    },     function fail(error) { 
        alert("An error has occurred: Code = " = error.code); 
    },   
   // “Capture Photo”按钮点击事件触发函数
   function capturePhoto() { // 使用设备上的摄像头拍照,并获得Base64编码字符串格式的图像
navigator.camera.getPicture(this.onPhotoURISuccess, this.onFail, { quality: 50 });
   },
       
   //“From Photo Library”/“From Photo Album”按钮点击事件触发函数
   function getPhoto(source) {  
    // 从设定的来源处获取图像文件URI
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,destinationType: destinationType.FILE_URI,sourceType: source });
   }<a href="#"  data-role="button" onclick="uploadphoto();">上传图片</a>
<a href="#" data-role="button" data-theme="b" onclick="capturePhoto();">拍照</a>
<a href="#" data-role="button" data-theme="b" onclick="getPhoto(pictureSource.PHOTOLIBRARY);">从相册选择</a>各位大神看看这段代码怎么进行函数式编程,imageURI这个参数怎么从onPhotoURISuccess传递到uploadphoto?imageURI是onPhotoURISuccess函数的自带的参数,怎么传给uploadphoto?函数式编程JavaScript

解决方案 »

  1.   

    浏览器内部完成的吧?跟event对象似地不懂,等大牛。
      

  2.   

    用全局变量就行了
    function onPhotoURISuccess(imageURI) {
         
            // 取消注释以查看图片文件的URI
            // console.log(imageURI);
            // 获取图片句柄
            var largeImage = document.getElementById('largeImage');
              
            // 取消隐藏的图像元素
            largeImage.style.display = 'block';
         
            // 显示拍摄的照片
            // 使用内嵌CSS规则来缩放图片
            largeImage.src = imageURI; 
            window.imgUrl = imageURI;
        }
    <a href="#"  data-role="button" onclick="uploadphoto(imgUrl);">上传图片</a>