覆盖<input type =“file”/> value属性

时间:2012-05-29 16:51:26

标签: javascript ios uiwebview file-io

可以覆盖标签中的value属性吗?我在JavaScript中的代码

var element = document.createElement('input');
element.type = 'FILE';
element.__defineGetter__('value',function(){ return 'ololo'; });
alert(element.value);

显示空字符串。我也尝试用原型

覆盖'value'
function BPFILEINPUT(value)
{
    this.value = value;
}
BPFILEINPUT.prototype = element;
var myFileInput = new BPFILEINPUT('ololo');
alert(myFileInput.value);

它起作用,但崩溃

form.appendChild(myFileInput);

我尝试在4shared.com

上传上传表单的测试
var uplElems = aUploadForm.elements;


   for (var i = 0; i < uplElems.length; i++) {
       var currentUploadElement = uplElems[i]
       if (currentUploadElement.type == 'file') {
           if (currentUploadElement.value == '') {
               // skip
           } else {
               if (!checkFileLength(currentUploadElement)) {
                  return false;
               }
               filesToUpload += getNumberOfSelectedFiles(currentUploadElement);
           }
       }
   }
   if (filesToUpload < 1) {
       alert('You didn\'t select any file to upload yet.');
       return false;
 }

更新

我使用UIWebView。

1 个答案:

答案 0 :(得分:2)

AFAIK,由于安全原因,您无法以编程方式设置<input type="file">的值。用户必须明确单击它以设置其值。