一个比较使用的javascript tip

一个比较使用的javascript tip。记录一下,方便以后查找。 :)
<html>
<head>

<title>tip</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

</head>

<body>
<script>


if(!document.attachEvent)
{
document.attachEvent = function(){document.addEventListener(arguments[0].substr(2),arguments[1],arguments[2])}
}

document.attachEvent("onmouseover",function(e)
{
var tip = "";

if(typeof(event)=="undefined"){
tip = e.target.getAttribute("tips")
}else{
e = event;
tip = e.srcElement.tips;
}


if(typeof(tip)!="undefined"&&tip.length>0)
{
var _tips = document.getElementById("myTip");

if(typeof(_tips)=="undefined"||_tips == null)
{
_tips = document.createElement("div");
_tips.id = "myTip";
_tips.style.position = "absolute";
_tips.style.width = "150px";
_tips.style.borderWidth = "1px";
_tips.style.borderStyle = "solid";
_tips.style.borderColor = "gray";
_tips.style.fontSize = "9pt";
_tips.style.backgroundColor = "#ffffff";
_tips.style.color = "#349045";


_tips.style.filter = "progid:DXImageTransform.Microsoft.Shadow(color=#999999,direction=135,strength=3)";
_tips.style.padding = "5px 8px 3px 8px";


document.body.appendChild(_tips);
_tips.style.display = "none";
}

_tips.style.display = "";

_tips.innerHTML = tip;
_tips.style.left = document.body.scrollLeft+e.clientX+10;
_tips.style.top = document.body.scrollTop+e.clientY+10;
}
}
);

document.attachEvent('onmouseout',function(e)
{
var _tips = document.getElementById("myTip");
if(_tips!=null)
{
_tips.style.display="none";
}
}
)
</script>

<a href="#" tips="自定义提示" >测试链接</a>
<a href="#" >测试链接</a>
<a href="#" tips="中华人民共和国中华人民共和国自中华人民共和国中华人民共和国自定义提示中华人民共和国中华人民共和国自定义提示中华人民共和国中华人民共和国自定义提示定义提示中华人民共和国中华人民共和国自中华人民共和国中华人民共和国自定义提示中华人民共和">测试链接</a>

</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是用 Vue 实现一个图片上传页面的基本步骤: 1. 在 Vue 项目中安装 axios 和 element-ui: ```bash npm install axios element-ui --save ``` 2. 在组件中引入 element-ui 的上传组件和 axios: ```javascript <template> <div> <el-upload class="upload-demo" :action="uploadUrl" :on-preview="handlePreview" :on-remove="handleRemove" :on-success="handleSuccess" :file-list="fileList" :auto-upload="false" :show-file-list="false" multiple> <el-button slot="trigger" size="small" type="primary">选取文件</el-button> <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button> <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> </el-upload> </div> </template> <script> import axios from 'axios' export default { name: 'ImageUpload', data() { return { fileList: [], uploadUrl: '/api/upload' // 上传图片的接口地址 } }, methods: { handlePreview(file) { console.log(file) }, handleRemove(file, fileList) { console.log(file, fileList) }, handleSuccess(response, file, fileList) { console.log(response, file, fileList) }, submitUpload() { this.$refs.upload.submit() } } } </script> ``` 3. 在组件中实现上传图片的方法: ```javascript handleSuccess(response, file, fileList) { console.log(response, file, fileList) // 将上传成功的图片添加到 fileList 中 this.fileList.push({ name: response.data.fileName, url: response.data.fileUrl }) }, submitUpload() { const formData = new FormData() // 添加要上传的图片到 formData 中 this.fileList.forEach(file => { formData.append('file', file.raw) }) // 使用 axios 发送 POST 请求上传图片 axios.post(this.uploadUrl, formData).then(response => { console.log(response) }).catch(error => { console.log(error) }) } ``` 4. 在服务端实现上传图片的接口: ```javascript const express = require('express') const multer = require('multer') const path = require('path') const app = express() // 设置上传文件的存储路径和文件名 const storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, './uploads/') }, filename: function (req, file, cb) { cb(null, Date.now() + path.extname(file.originalname)) } }) // 上传文件的限制 const limits = { fileSize: 1024 * 500, // 500kb files: 1 } // 创建 multer 实例 const upload = multer({ storage, limits }) // 处理上传文件的 POST 请求 app.post('/api/upload', upload.single('file'), (req, res) => { console.log(req.file) res.json({ status: 'success', data: { fileName: req.file.filename, fileUrl: `/uploads/${req.file.filename}` } }) }) // 启动服务 app.listen(3000, () => { console.log('Server is running at http://localhost:3000') }) ``` 以上就是用 Vue 实现图片上传页面的基本步骤,你可以根据自己的实际需求进行修改和完善。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值