客户端清空Iframe的内容

本文介绍了一种通过JavaScript操作iframe的方法,实现将其内部文本内容清空的功能。此技巧适用于需要动态更新或清除页面中嵌入的iframe元素场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

document.frames["frame1"].document.body.innerText = "";

 

暂记,备查

<template> <div class="upload-container"> <el-upload class="upload-demo" :auto-upload="false" :on-change="handleFileChange" :show-file-list="false" > <i class="el-icon-upload"></i> <div class="el-upload__text"> 将文件拖到此处,或点击选择文件 </div> </el-upload> <el-button type="primary" :disabled="!selectedFile" @click="uploadFile" class="mt-3" > 开始上传 </el-button> <el-progress v-if="progress > 0" :percentage="progress" :status="progressStatus" class="mt-3" ></el-progress> <div v-if="uploadResult" class="result-message"> <el-alert :title="uploadResult" :type="uploadSuccess ? 'success' : 'error'" show-icon ></el-alert> </div> </div> </template> <script> import axios from 'axios'; export default { name: 'UploadAttachment', data() { return { selectedFile: null, progress: 0, uploadSuccess: false, uploadResult: '' }; }, computed: { progressStatus() { return this.progress === 100 ? 'success' : undefined; } }, methods: { handleFileChange(file) { this.selectedFile = file.raw; this.uploadResult = ''; // 清除之前的上传结果 }, async uploadFile() { if (!this.selectedFile) return; const formData = new FormData(); formData.append('file', this.selectedFile); try { this.progress = 0; // 重置进度 const response = await axios.post('http://localhost:8080/upload', formData, { headers: { 'Content-Type': 'multipart/form-data' }, onUploadProgress: progressEvent => { this.progress = Math.round( (progressEvent.loaded * 100) / progressEvent.total ); } }); this.uploadSuccess = true; this.uploadResult = response.data; this.$notify.success({ title: '上传成功', message: '文件已成功上传到服务器' }); } catch (error) { this.uploadSuccess = false; this.uploadResult = `上传失败:${error.message}`; this.$notify.error({ title: '上传失败', message: '文件上传过程中出现错误' }); } finally { this.selectedFile = null; // 清空已选文件 setTimeout(() => { this.progress = 0; // 2秒后重置进度条 }, 2000); } } } }; </script> <style scoped> .upload-container { max-width: 500px; margin: 20px auto; padding: 20px; text-align: center; } .mt-3 { margin-top: 15px; } .result-message { margin-top: 20px; } </style> 这是个上传页面,在这页面可以看到上传的PDF文件,点击可以预览
最新发布
03-15
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值