当前位置: 首页 > news >正文

前端代码(一)

前端代码(一)

index.html

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script type="module" src="./math.js"></script><script type="module" src="./util.js"></script>
</head><script type="module">import {hello, getMsg} from './util.js'window.changeDivContent = function() {var divElement = document.getElementById('content')console.log('js i am coming...')divElement.innerHTML = getMsg()}
</script>
<body><h1>Demo</h1><div id="content"></div><button onclick="changeDivContent()">显示内容</button>
</body>
<script></script>
</html>

math.js

export function sum(a, b){return a+b
}function hello(){return 'hello math'
}

util.js

import {sum} from './math.js'export function hello() {return 'hello util'
}export function getMsg() {let sum_result =  sum(1, 2)console.log('sum_result:' + sum_result)return sum_result
}