我有一个为我编写的界面,我正在修改一下。我有这个功能来上传文件:
function importImage() {
var imageName = $("#image").val();
var tokens = imageName.split("\\");
var imageName = tokens[tokens.length-1];
if (imageName.length==0) {
alert("Image File Required");
return;
}
if ($("#userName").val().length==0) {
$("#userName").val(imageName);
}
popupShow("Uploading, please wait");
$('#imageImportForm').ajaxSubmit({
"error": function(){
alert("Unable to upload Image");
},
"dataType": "json",
"success": function(response, statusText, xhr) {
if (response["status"]!=1) {
popupRemove();
alert(response["message"]);
} else {
popupRemove();
getImages();
dataModel.addImage(0);
}
}
});
}
我发现在界面的其他部分,如果正在使用的图像中有空格,则可能会被破坏。所以为了解决这个问题,我希望在上传文件时消除文件中的空格。好奇我如何通过添加到这个java字符串:)来实现这一点。
这样的事情可能在开头:
var str = "#image";
var res = str.replace(/ /g,"_");