Vue获取下拉框中的值
vue
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
项目地址:https://gitcode.com/gh_mirrors/vu/vue
·
一、获取含有默认省的下拉框中的name值
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<script src="http://www.jq22.com/jquery/jquery-3.3.1.js"></script>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://cdn.bootcss.com/vue-resource/1.5.1/vue-resource.js"></script>
<body>
<form id="app5">
<select v-model="moren">
<option v-for="datas in province" selected="selected" v-if="datas.aname==moren" :value="datas.aname">{{datas.aname}}</option>
<option v-else :value="datas.aname">{{datas.aname}}</option>
<input type="button" @click="ceshi" value="提交" />
</select>
</form>
</body>
<script>
var app5 = new Vue({
el: '#app5',
data: {
province:'',
moren:'山东省',
},
methods: {
indexs:function(){
this.$http.post('{:url("Index/indexs")}')
.then(function(res){
this.province=res.data;
console.log(this.province);
})
.catch(function(error){
});
},
ceshi:function(){
console.log(this.moren);
}
},
created(){
this.indexs();
}
});
</script>
</html>
province:是中国所有的省。

二、获取含有默认省的下拉框中的id值
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<script src="http://www.jq22.com/jquery/jquery-3.3.1.js"></script>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://cdn.bootcss.com/vue-resource/1.5.1/vue-resource.js"></script>
<body>
<form id="app5">
<select v-model="moren">
<option v-for="datas in province" selected="selected" v-if="datas.aid==moren" :value="datas.aid">{{datas.aname}}</option>
<option v-else :value="datas.aid">{{datas.aname}}</option>
<input type="button" @click="ceshi" value="提交" />
</select>
</form>
</body>
<script>
var app5 = new Vue({
el: '#app5',
data: {
province:'',
moren:6,
},
methods: {
indexs:function(){
this.$http.post('{:url("Index/indexs")}')
.then(function(res){
this.province=res.data;
console.log(this.province);
})
.catch(function(error){
});
},
ceshi:function(){
console.log(this.moren);
}
},
created(){
this.indexs();
}
});
</script>
</html>

三、获取所有省的name值
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<script src="http://www.jq22.com/jquery/jquery-3.3.1.js"></script>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://cdn.bootcss.com/vue-resource/1.5.1/vue-resource.js"></script>
<body>
<form id="app5">
<select v-model="moren">
<option>请选择</option>
<option v-for="datas in province" :value="datas.aname">{{datas.aname}}</option>
<input type="button" @click="ceshi" value="提交" />
</select>
</form>
</body>
<script>
var app5 = new Vue({
el: '#app5',
data: {
province:'',
moren:'请选择',
},
methods: {
indexs:function(){
this.$http.post('{:url("Index/indexs")}')
.then(function(res){
this.province=res.data;
console.log(this.province);
})
.catch(function(error){
});
},
ceshi:function(){
console.log(this.moren);
}
},
created(){
this.indexs();
}
});
</script>
</html>

四、获取所有省的id值
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<script src="http://www.jq22.com/jquery/jquery-3.3.1.js"></script>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://cdn.bootcss.com/vue-resource/1.5.1/vue-resource.js"></script>
<body>
<form id="app5">
<select v-model="moren">
<option :value="2">请选择</option>
<option v-for="datas in province" :value="datas.aid">{{datas.aname}}</option>
<input type="button" @click="ceshi" value="提交" />
</select>
</form>
</body>
<script>
var app5 = new Vue({
el: '#app5',
data: {
province:'',
moren:'2',
},
methods: {
indexs:function(){
this.$http.post('{:url("Index/indexs")}')
.then(function(res){
this.province=res.data;
console.log(this.province);
})
.catch(function(error){
});
},
ceshi:function(){
console.log(this.moren);
}
},
created(){
this.indexs();
}
});
</script>
</html>

vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:4 个月前 )
9e887079
[skip ci] 1 年前
73486cb5
* chore: fix link broken
Signed-off-by: snoppy <michaleli@foxmail.com>
* Update packages/template-compiler/README.md [skip ci]
---------
Signed-off-by: snoppy <michaleli@foxmail.com>
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 1 年前
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐


所有评论(0)