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($) {