日期:2014-05-16  浏览次数:20362 次

javascript函数式编程

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();"&