<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>表单输入绑定</title>
<script src="vue.js"></script>
</head>
<body>
<div id = 'example-input'>
<p>文本:{{input_text}}</p>
<input v-model="input_text" />
</div>
<div id = 'example-textarea'>
<p>多行文本:{{input_textarea}}</p>
<textarea v-model="input_textarea"></textarea>
</div>
<div id = 'example-checkbox1'>
<span>单个复选框,绑定到布尔值:{{checked}}</span>
<input type="checkbox" id = 'checkbox' v-model='checked' />
<label for="checkbox">{{checked}}</label>
</div>
<br />
<div id = 'example-checkbox2'>
<span>多个复选框,绑定到数组:{{checkedNames}}</span>
<input type="checkbox" id = 'jack' value='jack' v-model='checkedNames' />
<label for="jack">jack</label>
<input type="checkbox" id = 'John' value='John' v-model='checkedNames' />
<label for="John">John</label>
<input type="checkbox" id = 'Mike' value='Mike' v-model='checkedNames' />
<label for="Mike">Mike</label>
</div>
<br />
<div id = 'example-radio'>
<span>单选按钮:</span><br />
<input type="radio" value="全红婵" id='quan' v-model="getName"/>
<label for="quan">全红婵</label>
<br />
<input type="radio" value="苏炳添" id='su' v-model="getName"/>
<label for="su">苏炳添</label>
<br />
<span>2020东京奥运会谁最出彩:{{getName}}</span>
</div>
<br />
<div id = 'selected-option'>
<span>下拉选择框:</span><br />
<select v-model="selectedName">
<option disabled value="">请选择乒乓大神</option>
<option>张继科</option>
<option>孙颖莎</option>
<option>马龙</option>
<option>张怡宁</option>
<option>陈梦</option>
</select><br />
<span>你的选择是:{{selectedName}}</span>
</div>
<br />
<div id = 'selected-option-multiple'>
<span>多选下拉框,内容动态渲染:</span><br />
<select multiple v-model="selectmultiple" >
<option v-for="option in options" v-bind:value="option.value">
{{option.text}}
</option>
</select><br />
<span>选择是:{{selectmultiple}}</span>
</div>
</body>
<script>
var exampleInput = new Vue({
el:"#example-input",
data:{
input_text:''
}
})
var exampleTextarea = new Vue({
el:'#example-textarea',
data:{
input_textarea:''
}
})
var exampleCheckbox1 = new Vue({
el:'#example-checkbox1',
data:{
checked :'false'
}
})
var exampleCheckbox2 = new Vue({
el:'#example-checkbox2',
data:{
checkedNames :[]
}
})
var exampleRadio = new Vue({
el:'#example-radio',
data:{
getName:''
}
})
var selectedOption = new Vue({
el:'#selected-option',
data:{
selectedName:''
}
})
var selectedOptionMultiple = new Vue({
el:'#selected-option-multiple',
data:{
selectmultiple:[],
options:[
{text:'石智勇',value:'shizhiyong'},
{text:'李发彬',value:'lifabin'},
{text:'汪周雨',value:'wangzhouyu'}
]
}
})
</script>
</html>
表单输入绑定
最新推荐文章于 2024-05-29 13:32:54 发布