我有一個HTML頁面,列出文件夾和普通文件的操作爲錨標籤中的所有文件名稱旁邊極大,誰用戶點擊一個文件操作說刪除,系統會提示用戶,如果他他肯定會刪除選定的文件。它幾乎完美地工作,但是,如果遇到空格和特殊字符的文件名:(My Track [Ezee] .mp3),它會失敗。是否有解決方法。任何幫助或指針在正確的方向將大大appreciated.Thanks檢索文件名的JavaScript/jQuery的
HTML
<tr class="filetable_entry_alt">
<td>
<input type="checkbox" name="sample10 with spaces (ezee's).jpg" value="file">
</td>
<td>
<a href="/mnt/sdcard/DCIM/sample10 with spaces (ezee's).jpg" title="sample10 with spaces (ezee's).jpg" class="thumb" rel="cb">
<img src="/thumbnail.wft?image=/mnt/sdcard/DCIM/sample10 with spaces (ezee's).jpg&kind=micro&lm=1308828676000" alt="">
<b>
<img src="/thumbnail.wft?image=/mnt/sdcard/DCIM/sample10 with spaces (ezee's).jpg&kind=micro&lm=1308828676000" alt="" style="width:150px; height:150px;">
</b>
</a>
</td>
<td>
<a href="/mnt/sdcard/DCIM/sample10 with spaces (ezee's).jpg" title="sample10 with spaces (ezee's).jpg">
sample10 with spaces (ezee's).jpg
</a>
</td>
<td>
06/23/11 12:31 PM
</td>
<td>
1.76 MB
</td>
<td>
<a href="#" onclick="return confirmDel('/mnt/sdcard/DCIM/sample10 with spaces (ezee's).jpg', '/mnt/sdcard/DCIM/?');">
delete
</a> |
<a href="#" onclick="return confirmRen('/mnt/sdcard/DCIM/','sample10 with spaces (ezee's).jpg','/mnt/sdcard/DCIM/?');">
rename
</a>|
<a href="#" onclick="return confirmCopy('/mnt/sdcard/DCIM/','sample10 with spaces (ezee's).jpg', '/mnt/sdcard/DCIM/?');">
copy
</a>
</td>
JS代碼
var selectedFile = 'noFile';
var selectedFile2 = 'noFile';
function confirmDel(t, p) {
var confirmDeltxt = 'Are you sure you want to delete ' + t + '?';
selectedFile = decodeURIComponent(t);
selectedFile2 = decodeURIComponent(p);
jQuery.prompt(confirmDeltxt, {
callback: confirmDelcallback,
buttons: {
Delete: 'ok',
Cancel: 'cancel'
}
});
return false;
}
function confirmDelcallback(v, m, f) {
if (v != undefined && v == 'ok') {
var form = document.forms.filelist;
form.action.value = 'delete';
form.data_file.value = selectedFile2 + "/" + selectedFile;
form.submit();
}
}
function confirmRen(p, f, cp) {
selectedFile = decodeURIComponent(p);
selectedFile2 = decodeURIComponent(f);
var confirmRentxt = 'Enter new file name:<br /><br /><input type="text" id="newPath" name="newPath" value="' + f + '" />';
jQuery.prompt(confirmRentxt, {
submit: confirmRensubmit,
callback: confirmRencallback,
buttons: {
Rename: 'ok',
Cancel: 'cancel'
}
});
return false;
}
function confirmRensubmit(v, m, f) {
an = m.children('#newPath');
if (v == 'ok') {
if (f.newPath == "") {
an.css("border", "solid #ff0000 1px");
return false;
}
}
return true;
}
感謝您指出了out.Will整理出來。 – kalz