自己写了一个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 分钟前
41 .UDP -3 群聊功能实现:线程池助力多客户端通信
linux·开发语言·网络·数据结构·c++·网络协议·udp
zly88653726 分钟前
windsurf rules与skill的使用
linux·c语言·开发语言·驱动开发
笨笨马甲12 分钟前
Qt network开发
开发语言·qt
不染尘.17 分钟前
排序算法详解1
开发语言·数据结构·c++·算法·排序算法
Via_Neo18 分钟前
JAVA中对数的表达,将浮点数转为保留指定位数的字符串
java·开发语言
Lzh编程小栈23 分钟前
数据结构与算法——单链表超详解(C语言完整实现 + 面试高频题)
c语言·开发语言·面试
沐知全栈开发24 分钟前
Shell 函数
开发语言
2301_8166512225 分钟前
移动语义在容器中的应用
开发语言·c++·算法
FlyWIHTSKY27 分钟前
Vue 3 onMounted 中控制同步与异步执行策略
前端·javascript·vue.js
2401_8579182927 分钟前
实时数据处理中的C++应用
开发语言·c++·算法