在使用weui的滑块删除组件的时候,有时候会出现这种错误
Uncaught TypeError: $(…).swipeout is not a function
原因是在引用weui的时候,也引用了jquery,并且jquery引用在这段代码的前面,造成冲突
$('.delete-swipeout').click(function() { $(this).parents('.weui-cell').remove() console.log(123)})$('.close-swipeout').click(function() { $(this).parents('.weui-cell').swipeout('close') console.log(456)})$('.weui-cell_swiped').swipeout('open')//就是这里报错$(document).on("swipeout-open", '.weui-cell_swiped', function() { //监听打开触发 console.log(788)})$(document).on("swipeout-close", '.weui-cell_swiped', function() { //监听关闭触发 console.log(1212)})解决办法:
将jquery引用放到上面那段代码后面
<script type="text/javascript"> $('.delete-swipeout').click(function() { $(this).parents('.weui-cell').remove() console.log(123) }) $('.close-swipeout').click(function() { $(thhttps://www.3tt.net/?mod=artinfo&aid=57is).parents('.weui-cell').swipeout('close') console.log(456) }) $('.weui-cell_swiped').swipeout('open') $(document).on("swipeout-open", '.weui-cell_swiped', function() { //监听打开触发 console.log(788) }) $(document).on("swipeout-close", '.weui-cell_swiped', function() { //监听关闭触发 console.log(1212) }) </script> <script src="js/jquery.js"></script><!-- 引用在后面 -->