自己写了一个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 小时前
02Numpy基础(上)
开发语言·python
TheBestRucy3 小时前
Python 九阳神功之贰:面向对象(下)
开发语言·python
AI_小站4 小时前
刚面完百度的 Agent 开发岗,我才发现:世界就是个巨大的草台班子
java·开发语言·人工智能·spring·百度·langchain
felixking5 小时前
C++20 协程
开发语言·c++·协程
Zane1994126 小时前
CAS 与原子类:Java 如何实现无锁编程
java·开发语言
码农颜7 小时前
6.3 主函数流程剖析
开发语言·php
TheBestRucy7 小时前
Python 九阳神功:从零筑基到线程飞升
服务器·开发语言·网络·人工智能·python
研☆香7 小时前
聊一聊前端的常见字 关键字
开发语言·前端·javascript
草莓橙子碗8 小时前
Claude 使用指南
开发语言·python
longxiaozhang68 小时前
C# Array类:数组其实没那么难
开发语言·c#