MVVM模式
jquery.js
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>demo704</title>
</head><body><div id="app"><button>Click me</button></div><script src="./js/jquery.min.js">var btn = document.getElementsByTagName('button');console.log(btn);var showBtn = true;if (showBtn) {var btn = $('<button>Click me</button>');btn.on('click', function() {console.log('clicked');});$('#app').append(btn);}</script>
</body></html>
vue.js
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>demo704</title>
</head><body><div id="app"><button v-if="showBtn" v-on:click="handleClick">click me</button><p>{{name}}</p></div><script src="./js/vue.js">var app = new Vue({el: '#app',data: {showBtn: true,name: 'geyao'},methods: {handleClick: function() {console.log('clicked')}}})</script>
</body></html>