forked from 471314748/xiaotexiao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
04给字符串首字母大写.html
36 lines (36 loc) · 932 Bytes
/
04给字符串首字母大写.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!DOCTYPE html>
<html lang="zh-CH">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<h2>把i-miss-you变成I Miss You</h2>
<input type="text" v-model='val'>
<!-- 把i-miss-you变成I Miss You -->
<button @click='dianji'>按钮</button>
</div>
</body>
<script>
var app = new Vue({
el: '#app',
data: {
val: 'i-miss-you'
},
methods: {
dianji(){
var val1 = this.val.split('-')
console.log(val1);
this.val=""
for (var key in val1) {
// 遍历数组,每一项的第一个字符大写,拼接从第一项之后的字符
this.val+=val1[key][0].toUpperCase()+val1[key].substring(1, val1[key].length)+" "
}
}
},
})
</script>
</html>