JavaScript获取标签

可以通过tag或则tag的id去获取:
如果获取一个标签type为file的的元素:

var file = document.getElementById(fileInputId);

获取该标签下其他元素的值:
通过id去获取

$("#"+fileInputId).attr("accept");

jquery中ajax请求实例:

$.ajax({
            url : contextPath + '/ajax/system/uploadfile.htm',
            data : {
                fileName : filename,
                fileSize : file.size,
                containerId : containerId,
                userType : userType,
                fileType : fileType,
                extensionType : extensionType
            },
            type : 'get',
            cache : false,
            dataType : 'json',
            success : function(data) {
                if(data.success) {
                    showProcess('uploadFile', data.message.fileCode.split(".")[0], filename);
                    doUpload(fileInputId, file, data.message.fileCode, data.message.filePath, data.message.OSSAccessKeyId, data.message.policy, data.message.signature, data.message.bucketName, data.message.siteName, uploadCompleteFun, uploadProgressFun, uploadFailedFun, uploadCanceledFun);
                } else {
                    alert(data.error);
                }
            },
            error : function() {
                alert("上传请求被拒绝");
            }
        });
        if(fileInputTextId != null) {
            $("#"+fileInputTextId).val(filename);
        }

你可能感兴趣的:(JavaScript获取标签)