我在“ uploadify ”插件中添加了文本框,用于从用户获取文件说明,并将其传递给 scriptData 。
function loadSwf(){
$("#fileuploader").fileUpload({
'uploader': "@Url.Content("~/Scripts/FileUpload/uploader.swf")",
'cancelImg': "@Url.Content("~/Content/Images/clearBtn.png")",
'buttonText': 'Browse Files',
//'buttonImg' : "@Url.Content("~/Content/Images/attachDoc.png")",
'script': "@Url.Content("~/Documents/Upload/")",
'folder': "@Url.Content("~/Documents/")",
//'fileDesc': 'Documents Files',
'fileExt': '*.pdf;*.doc;*.ppt;*.xls',
'multi': true,
'auto': false,
'scriptData': {'Description': $('[id="DescriptionTxt"]').val()}
});
}
通过控制器MVC3
..
问题是我的所有文本框都有相同的“ ID和名称”,那么如何隔离或获取每个文本框字段的值?
var flashVer = -1;
var activityId = $('[id="ActivityID"]').val();
if (navigator.plugins != null && navigator.plugins.length > 0) {
if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
var descArray = flashDescription.split(" ");
var tempArrayMajor = descArray[2].split(".");
var versionMajor = tempArrayMajor[0];
var versionMinor = tempArrayMajor[1];
var versionRevision = descArray[3];
if (versionRevision == "") {
versionRevision = descArray[4]
}
if (versionRevision[0] == "d") {
versionRevision = versionRevision.substring(1)
}
else {
if (versionRevision[0] == "r") {
ersionRevision = versionRevision.substring(1);
if (versionRevision.indexOf("d") > 0) {
versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"))
}
}
}
var flashVer = versionMajor + "." + versionMinor + "." + versionRevision
}
}
else {
if ($.browser.msie) {
var version;
var axo;
var e;
try {
axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
version = axo.GetVariable("$version")
}
catch (e) {
}
flashVer = version.replace("WIN ", "").replace(",", ".")
}
}
flashVer = flashVer.split(".")[0];
if (jQuery) {
(function (a) {
a.extend(a.fn,
{
fileUpload: function (b) {
if (flashVer >= 9) {
a(this).each(function () {
settings = a.extend({
uploader: "uploader.swf",
script: "uploader.php",
folder: "",
height: 30,
width: 110,
cancelImg: "cancel.png",
wmode: "opaque",
scriptAccess: "sameDomain",
fileDataName: "Filedata",
displayData: "percentage",
onInit: function () { },
onSelect: function () { },
onCheck: function () { },
onCancel: function () { },
onError: function () { },
onProgress: function () { },
onComplete: function () { }
}, b);
var d = location.pathname;
d = d.split("/");
d.pop();
d = d.join("/") + "/";
var f = "&pagepath=" + d;
if (settings.buttonImg) {
f += "&buttonImg=" + escape(settings.buttonImg)
}
if (settings.buttonText) {
f += "&buttonText=" + escape(settings.buttonText)
}
if (settings.rollover) {
f += "&rollover=true"
}
f += "&script=" + settings.script;
f += "&folder=" + escape(settings.folder);
if (settings.scriptData) {
var g = "";
for (var c in settings.scriptData) {
g += "&" + c + "=" + settings.scriptData[c]
}
f += "&scriptData=" + escape(g)
}
f += "&btnWidth=" + settings.width;
f += "&btnHeight=" + settings.height;
f += "&wmode=" + settings.wmode;
if (settings.hideButton) {
f += "&hideButton=true"
}
if (settings.fileDesc) {
f += "&fileDesc=" + settings.fileDesc + "&fileExt=" + settings.fileExt
}
if (settings.multi) {
f += "&multi=true"
}
if (settings.auto) {
f += "&auto=true"
}
if (settings.sizeLimit) {
f += "&sizeLimit=" + settings.sizeLimit
}
if (settings.simUploadLimit) {
f += "&simUploadLimit=" + settings.simUploadLimit
}
if (settings.checkScript) {
f += "&checkScript=" + settings.checkScript
}
if (settings.fileDataName) {
f += "&fileDataName=" + settings.fileDataName
}
if (a.browser.msie) {
flashElement = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + settings.width + '" height="' + settings.height + '" id="' + a(this).attr("id") + 'Uploader" class="fileUploaderBtn"><param name="movie" value="' + settings.uploader + "?fileUploadID=" + a(this).attr("id") + f + '" /><param name="quality" value="high" /><param name="wmode" value="' + settings.wmode + '" /><param name="allowScriptAccess" value="' + settings.scriptAccess + '"><param name="swfversion" value="9.0.0.0" /></object>'
}
else {
flashElement = '<embed src="' + settings.uploader + "?fileUploadID=" + a(this).attr("id") + f + '" quality="high" width="' + settings.width + '" height="' + settings.height + '" id="' + a(this).attr("id") + 'Uploader" class="fileUploaderBtn" name="' + a(this).attr("id") + 'Uploader" allowScriptAccess="' + settings.scriptAccess + '" wmode="' + settings.wmode + '" type="application/x-shockwave-flash" />'
}
if (settings.onInit() !== false) {
a(this).css("display", "none");
if (a.browser.msie) {
a(this).after('<div id="' + a(this).attr("id") + 'Uploader"></div>');
document.getElementById(a(this).attr("id") + "Uploader").outerHTML = flashElement
}
else {
a(this).after(flashElement)
}
a("#" + a(this).attr("id") + "Uploader").after('<div id="' + a(this).attr("id") + 'Queue" class="fileUploadQueue"></div>')
}
a(this).bind("rfuSelect",
{
action: settings.onSelect
},
function (j, h, i) {
if (j.data.action(j, h, i) !== false) {
var k = Math.round(i.size / 1024 * 100) * 0.01;
var l = "KB";
if (k > 1000) {
k = Math.round(k * 0.001 * 100) * 0.01;
l = "MB"
}
var m = k.toString().split(".");
if (m.length > 1) {
k = m[0] + "." + m[1].substr(0, 2)
}
else {
k = m[0]
}
if (i.name.length > 20) {
fileName = i.name.substr(0, 20) + "..."
}
else {
fileName = i.name
}
a("#" + a(this).attr("id") + "Queue").append('<div id="' + a(this).attr("id") + h + '" class="fileUploadQueueItem"><div class="cancel"><a href="javascript:$(\'#' + a(this).attr("id") + "').fileUploadCancel('" + h + '\')"><img src="' + settings.cancelImg + '" border="0" /></a></div><span class="fileName">Document Name :' + fileName + "</br>Documents Size : (" + k + l + ')</span><span class="percentage"> </span></br><div class="Description">Description : <input type="textbox" id="des" name="des" class="des"></div><div class="fileUploadProgress" style="width: 100%;"><div id="' + a(this).attr("id") + h + 'ProgressBar" class="fileUploadProgressBar" style="width: 1px; height: 3px;"></div></div></div>')
}
});
最后一行包含我添加了div description 的代码和带有id&amp;的文本框的代码name =“des”