自己写了一个jq的toast弹窗框架引入之后调用报错$.toast is not a function

toast.js

复制代码
(function($) {
$.toast = function(message) {
    var toast = $('#toast');
    toast.find('.toast-message').text(message);
    toast.fadeIn(function () {
        setTimeout(function () {
            toast.fadeOut();
        }, 3000); // 持续时间3秒
    })

    toast.click(function(){
        toast.fadeOut();
    })
}
})

页面是这样引入的

复制代码
<script src="./js/toast.js"></script>
复制代码
<div id="toast" style="display: none;">
    <div class="toast-message"></div>
</div>

<style>

复制代码
#toast{
    font-size: 14px;
    position: fixed;
    top: 50%;
    left: 50%;
    width: 80%;
    transform: translate(-50%, -50%);
    background-color: #fff;
    border: 1px solid #ccc;
    padding: 20px;
    border-radius: 5px;
    box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
    z-index: 99999;
}

</style>

使用

复制代码
$.toast('请输入要充值的抖音号')

却报错了$.toast is not a function

最后把js的地方(function($) {

改成

复制代码
jQuery(document).ready(function($) {
相关推荐
阿里嘎多学长3 分钟前
2026-01-02 GitHub 热点项目精选
开发语言·程序员·github·代码托管
XiaoYu20027 分钟前
第8章 Three.js入门
前端·javascript·three.js
天远云服13 分钟前
Go语言高并发实战:集成天远手机号码归属地核验API打造高性能风控中台
大数据·开发语言·后端·golang
这个一个非常哈18 分钟前
element之,自定义form的label
前端·javascript·vue.js
2501_9418771334 分钟前
在法兰克福企业级场景中落地零信任安全架构的系统设计与工程实践分享
开发语言·php
李瑞丰_liruifengv34 分钟前
Claude Agent SDK 最简玩法:几行代码配合 Markdown 轻松搭建 Agent
javascript·人工智能·程序员
bobringtheboys41 分钟前
[el-tag]使用多个el-tag,自动判断内容是否超出
前端·javascript·vue.js
leiming644 分钟前
c++ QT 开发第二天,用ui按钮点亮实体led
开发语言·qt·ui
尽欢i44 分钟前
用 return“瘦身“if-else:让代码少嵌套、好维护
前端·javascript
程序员Agions1 小时前
小程序"邪修"秘籍:那些官方文档不会告诉你的骚操作
前端·javascript