前端实现点击拨号、下载文件功能

    技术2022-07-10  152

    1、在js中创建a标签实现报号功能

    点击电话图标跳转到手机拨号页面 实现拨号功能的a标签写法:

    <a href="tel:13764567708"/>

    js 中实现拨号功能方法:

    // 拨号 传入需要拨打的电话号码 dial(phoneNum) { const a = document.createElement('a') a.setAttribute('href', '')// href链接 a.setAttribute('target', '_self')// href链接 a.href = 'tel:' + phoneNum a.click()// 自执行点击事件 console.log(phoneNum, '拨号') }

    2、在js中创建a标签实现下载功能

    // 下载 需要后台传入下载文件的url downLoad(data) { const a = document.createElement('a') // 创建a标签 a.setAttribute('download', '')// download属性 a.setAttribute('href', '')// href链接 a.setAttribute('target', '_self')// href链接 //this.baseApi 改成服务器的IP即可 a.href的值为下载的链接 a.href = this.baseApi + '/' + data.fileUrl.substring(data.fileUrl.indexOf('file')).replace(/\\/, '/') a.click()// 自执行点击事件 }
    Processed: 0.016, SQL: 9