• 当前标签:js

程序开发 JS ES6数组的两个值替换位置

在 ES6 中,你可以使用数组解构赋值来交换数组中两个值的位置。以下是一个示例: let array = [1, 2, 3, 4]; [array[0], array[1]] = [array[1], array[0]]; console.log(array); // 输出 [2, 1, 3, 4] 在这个例子中,我们

2023-08-24 18:08:33 35 0 0
阅读详情

程序开发 解决js toFixed 四舍五入遇5不进位问题

const a = 7.55; console.log(a.toFixed(1)) // 7.5 比如上面这代码,如果作为四舍五入计算的话,就会出现遇到5不进位的问题 具体原因可以参考这篇文章 js - tofixed精度丢失问题 附上上面文章的解决方案的ts版(重写Number.prototype.toFixed)

2022-10-25 15:33:31 467 0 0
阅读详情

程序开发 vue 中对城市列表根据首字母进行排序

vue中根据城市的首字母a-z进行排序 先安装 js-pinyin 依赖: npm i --save js-pinyin 然后在组件中引入: import pyjs from 'js-pinyin' export default { async mounted() { let city = [ { name: '北京'

2018-12-14 11:11:34 3115 0 0
阅读详情

程序开发 JS原生滚动到指定元素位置

使用JS原生API Element.scrollIntoView() ;(有部分浏览器不支持) https://developer.mozilla.org/zh-CN/docs/Web/API/Element/scrollIntoView Element.scrollIntoView() 方法让当前的元素滚动到浏览器窗

2018-06-12 16:38:31 3664 2 0
阅读详情

程序开发 paging.js插件翻页

在需要添加分页的地方添加以下html代码: <div id="page"></div> js代码: $("#page").paging({         pageNo: that.page, // 传入初始         totalPage: that.totalPage, //传入总页数

2018-01-16 10:42:45 1617 0 0
阅读详情

程序开发 js点击复制文字或链接方法

js点击复制一段文字或者链接: $('#btn').click(function(e){     let url = e.currentTarget.dataset.url;     $("body").after("<textarea cols='1' rows='1' id='copyContent'>

2018-01-02 10:24:28 1765 0 0
阅读详情

程序开发 鼠标向上、向下滚动时执行事件

原理:拿当前的scrollTop和之前的scrollTop对比 如果变大了,表示向下滚动(scrollTop值变大); 如果变小了,表示向上滚动(scrollTop值变小)。 $(document).ready(function(){     var p=0,t=0;     $(window).scroll(func

2017-12-22 13:58:33 1188 4 0
阅读详情
  • 1
  • 2
前往