关于angularjs的绑定事件
来源:互联网 发布:linux shell wait 编辑:程序博客网 时间:2024/05/01 16:46
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="../angular/angular.js"></script>
<script>
var app=angular.module("myapp",[]);
app.controller("myctrl",function($scope){
//初始值
$scope.tid="";
$scope.tname="";
$scope.tprice="";
$scope.xid="";
$scope.xname="";
$scope.xprice="";
$scope.ttishi=false;
$scope.xtishi=false;
$scope.biao=[
{
"id":20,
"name":"华为",
"price":2888,
state:false
},
{
"id":60,
"name":"苹果x",
"price":9888,
state:false
},
{
"id":90,
"name":"三星",
"price":6888,
state:false
},
{
"id":600,
"name":"锤子",
"price":1888,
state:false
}
];
//查询
$scope.sel="";
//分级
$scope.fenji="--请选择--";
$scope.fshow=function(price){
if($scope.fenji=="--请选择--"){
return true;
}
var cs=$scope.fenji.split("-");
if(price<cs[0]||price>cs[1]){
return false;
}else{
return true;
}
}
//排序
$scope.paixu="+id";
//全选
$scope.cheda=false;
$scope.cheda1=function(){
if($scope.cheda){
for(x in $scope.biao){
$scope.biao[x].state=true;
}
}else{
for(x in $scope.biao){
$scope.biao[x].state=false;
}
}
}
//反选
$scope.chexiao1=function(){
var a=false;
for(x in $scope.biao){
if(!$scope.biao[x].state){
a=true;
}
}
if(a){
$scope.cheda=false;
}else{
$scope.cheda=true;
}
}
//批量删除
$scope.deleteall=function(){
var s=[];
for(x in $scope.biao){
if($scope.biao[x].state){
s.push($scope.biao[x].name);
}
}
if(s.length<=0){
alert("请选择");
}
for(x in s){
for(x2 in $scope.biao){
if(s[x]==$scope.biao[x2].name){
$scope.biao.splice(x2,1);
}
}
}
}
//单个删除
$scope.delete=function(name){
for(x in $scope.biao){
if(name==$scope.biao[x].name){
$scope.biao.splice(x,1);
}
}
}
//添加
$scope.flag=false;
$scope.tj=function(){
$scope.flag2=false;
if($scope.flag){
$scope.flag=false;
}else{
$scope.flag=true;
}
}
//修改
$scope.flag2=false;
$scope.update=function(l){
$scope.flag=false;
$scope.flag2=true;
$scope.xid=l.id;
$scope.xname=l.name;
$scope.xprice=l.price;
}
//添加 验证
$scope.zu=[];
$scope.tbaocun=function(){
$scope.zu=[];
if($scope.tid==""){
$scope.zu.push("id不能为空");
}else{
if(isNaN($scope.tid)){
$scope.zu.push("id必须为数字");
}
}
if($scope.tname==""){
$scope.zu.push("名字不能为空");
}
if($scope.tprice==""){
$scope.zu.push("价格不能为空");
}else{
if(isNaN($scope.tprice)){
$scope.zu.push("价格必须为数字");
}
}
if( $scope.zu.length>0){
$scope.ttishi=true;
}else{
$scope.ttishi=false;
var k={
"id":parseInt($scope.tid),
"name":$scope.tname,
"price":parseInt($scope.tprice),
state:false
}
$scope.biao.push(k);
}
}
//修改 验证
$scope.zu2=[];
$scope.xbaocun=function(){
$scope.zu2=[];
if($scope.xname==""){
$scope.zu2.push("名字不能为空");
}
if($scope.xprice==""){
$scope.zu2.push("价格不能为空");
}else{
if(isNaN($scope.xprice)){
$scope.zu2.push("价格必须为数字");
}
}
if( $scope.zu2.length>0){
$scope.xtishi=true;
}else{
$scope.xtishi=false;
for(x in $scope.biao){
if($scope.xid==$scope.biao[x].id){
$scope.biao[x].name=$scope.xname;
$scope.biao[x].price=parseInt($scope.xprice);
}
}
}
}
});
</script>
<style>
table tr:nth-child(odd){
background-color: cornflowerblue;
}
table tr:nth-child(even){
background-color: burlywood;
}
</style>
</head>
<body ng-app="myapp" ng-controller="myctrl">
<center>
查询<input type="text" ng-model="sel">
分级<select ng-model="fenji">
<option>--请选择--</option>
<option>0-2001</option>
<option>2001-4001</option>
<option>4001-6001</option>
<option>6001-8001</option>
<option>8001-15001</option>
</select>
排序<select ng-model="paixu">
<option value="+id">排序方式</option>
<option value="+id">id正序</option>
<option value="-id">id逆序</option>
<option value="+price">价格正序</option>
<option value="-price">价格逆序</option>
</select>
<button ng-click="deleteall()">批量删除</button><br />
<table border="1px solid" cellpadding="10px" cellspacing="0px">
<thead>
<tr style="background-color: #8F8F8F;">
<td><input type="checkbox" ng-model="cheda" ng-click="cheda1()"></td>
<td>产品编号</td>
<td>产品名称</td>
<td>产品价格</td>
<td>操作</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in biao | filter:{'name':sel} | orderBy:paixu" ng-show="fshow(x.price)" onmouseover="this.style.cursor='hand'">
<td><input type="checkbox" ng-model="x.state" ng-click="chexiao1()"></td>
<td>{{x.id}}</td>
<td>{{x.name}}</td>
<td>{{x.price}}</td>
<td>
<button ng-click="delete(x.name)">删除</button>
<button ng-click="update(x)">修改</button>
</td>
</tr>
</tbody>
</table><br />
<button ng-click="tj()">添加</button>
<div ng-show="flag" style="border:1px solid;" >
<h4>添加界面</h4>
id:<input type="text" ng-model="tid"><br />
姓名:<input type="text" ng-model="tname"><br />
价格:<input type="text" ng-model="tprice"><br />
<button ng-click="tbaocun()">保存</button><br />
<div ng-show="ttishi">
<ul>
<li ng-repeat="x in zu">{{x}}</li>
</ul>
</div>
</div>
<div ng-show="flag2" style="border:1px solid;" >
<h4>修改界面</h4>
id:<input type="text" disabled="disabled" ng-model="xid"><br />
姓名:<input type="text" ng-model="xname"><br />
价格:<input type="text" ng-model="xprice"><br />
<button ng-click="xbaocun()">保存</button><br />
<div ng-show="xtishi">
<ul>
<li ng-repeat="x in zu2">{{x}}</li>
</ul>
</div>
</div>
</center>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="../angular/angular.js"></script>
<script>
var app=angular.module("myapp",[]);
app.controller("myctrl",function($scope){
//初始值
$scope.tid="";
$scope.tname="";
$scope.tprice="";
$scope.xid="";
$scope.xname="";
$scope.xprice="";
$scope.ttishi=false;
$scope.xtishi=false;
$scope.biao=[
{
"id":20,
"name":"华为",
"price":2888,
state:false
},
{
"id":60,
"name":"苹果x",
"price":9888,
state:false
},
{
"id":90,
"name":"三星",
"price":6888,
state:false
},
{
"id":600,
"name":"锤子",
"price":1888,
state:false
}
];
//查询
$scope.sel="";
//分级
$scope.fenji="--请选择--";
$scope.fshow=function(price){
if($scope.fenji=="--请选择--"){
return true;
}
var cs=$scope.fenji.split("-");
if(price<cs[0]||price>cs[1]){
return false;
}else{
return true;
}
}
//排序
$scope.paixu="+id";
//全选
$scope.cheda=false;
$scope.cheda1=function(){
if($scope.cheda){
for(x in $scope.biao){
$scope.biao[x].state=true;
}
}else{
for(x in $scope.biao){
$scope.biao[x].state=false;
}
}
}
//反选
$scope.chexiao1=function(){
var a=false;
for(x in $scope.biao){
if(!$scope.biao[x].state){
a=true;
}
}
if(a){
$scope.cheda=false;
}else{
$scope.cheda=true;
}
}
//批量删除
$scope.deleteall=function(){
var s=[];
for(x in $scope.biao){
if($scope.biao[x].state){
s.push($scope.biao[x].name);
}
}
if(s.length<=0){
alert("请选择");
}
for(x in s){
for(x2 in $scope.biao){
if(s[x]==$scope.biao[x2].name){
$scope.biao.splice(x2,1);
}
}
}
}
//单个删除
$scope.delete=function(name){
for(x in $scope.biao){
if(name==$scope.biao[x].name){
$scope.biao.splice(x,1);
}
}
}
//添加
$scope.flag=false;
$scope.tj=function(){
$scope.flag2=false;
if($scope.flag){
$scope.flag=false;
}else{
$scope.flag=true;
}
}
//修改
$scope.flag2=false;
$scope.update=function(l){
$scope.flag=false;
$scope.flag2=true;
$scope.xid=l.id;
$scope.xname=l.name;
$scope.xprice=l.price;
}
//添加 验证
$scope.zu=[];
$scope.tbaocun=function(){
$scope.zu=[];
if($scope.tid==""){
$scope.zu.push("id不能为空");
}else{
if(isNaN($scope.tid)){
$scope.zu.push("id必须为数字");
}
}
if($scope.tname==""){
$scope.zu.push("名字不能为空");
}
if($scope.tprice==""){
$scope.zu.push("价格不能为空");
}else{
if(isNaN($scope.tprice)){
$scope.zu.push("价格必须为数字");
}
}
if( $scope.zu.length>0){
$scope.ttishi=true;
}else{
$scope.ttishi=false;
var k={
"id":parseInt($scope.tid),
"name":$scope.tname,
"price":parseInt($scope.tprice),
state:false
}
$scope.biao.push(k);
}
}
//修改 验证
$scope.zu2=[];
$scope.xbaocun=function(){
$scope.zu2=[];
if($scope.xname==""){
$scope.zu2.push("名字不能为空");
}
if($scope.xprice==""){
$scope.zu2.push("价格不能为空");
}else{
if(isNaN($scope.xprice)){
$scope.zu2.push("价格必须为数字");
}
}
if( $scope.zu2.length>0){
$scope.xtishi=true;
}else{
$scope.xtishi=false;
for(x in $scope.biao){
if($scope.xid==$scope.biao[x].id){
$scope.biao[x].name=$scope.xname;
$scope.biao[x].price=parseInt($scope.xprice);
}
}
}
}
});
</script>
<style>
table tr:nth-child(odd){
background-color: cornflowerblue;
}
table tr:nth-child(even){
background-color: burlywood;
}
</style>
</head>
<body ng-app="myapp" ng-controller="myctrl">
<center>
查询<input type="text" ng-model="sel">
分级<select ng-model="fenji">
<option>--请选择--</option>
<option>0-2001</option>
<option>2001-4001</option>
<option>4001-6001</option>
<option>6001-8001</option>
<option>8001-15001</option>
</select>
排序<select ng-model="paixu">
<option value="+id">排序方式</option>
<option value="+id">id正序</option>
<option value="-id">id逆序</option>
<option value="+price">价格正序</option>
<option value="-price">价格逆序</option>
</select>
<button ng-click="deleteall()">批量删除</button><br />
<table border="1px solid" cellpadding="10px" cellspacing="0px">
<thead>
<tr style="background-color: #8F8F8F;">
<td><input type="checkbox" ng-model="cheda" ng-click="cheda1()"></td>
<td>产品编号</td>
<td>产品名称</td>
<td>产品价格</td>
<td>操作</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in biao | filter:{'name':sel} | orderBy:paixu" ng-show="fshow(x.price)" onmouseover="this.style.cursor='hand'">
<td><input type="checkbox" ng-model="x.state" ng-click="chexiao1()"></td>
<td>{{x.id}}</td>
<td>{{x.name}}</td>
<td>{{x.price}}</td>
<td>
<button ng-click="delete(x.name)">删除</button>
<button ng-click="update(x)">修改</button>
</td>
</tr>
</tbody>
</table><br />
<button ng-click="tj()">添加</button>
<div ng-show="flag" style="border:1px solid;" >
<h4>添加界面</h4>
id:<input type="text" ng-model="tid"><br />
姓名:<input type="text" ng-model="tname"><br />
价格:<input type="text" ng-model="tprice"><br />
<button ng-click="tbaocun()">保存</button><br />
<div ng-show="ttishi">
<ul>
<li ng-repeat="x in zu">{{x}}</li>
</ul>
</div>
</div>
<div ng-show="flag2" style="border:1px solid;" >
<h4>修改界面</h4>
id:<input type="text" disabled="disabled" ng-model="xid"><br />
姓名:<input type="text" ng-model="xname"><br />
价格:<input type="text" ng-model="xprice"><br />
<button ng-click="xbaocun()">保存</button><br />
<div ng-show="xtishi">
<ul>
<li ng-repeat="x in zu2">{{x}}</li>
</ul>
</div>
</div>
</center>
</body>
</html>
阅读全文
0 0
- 关于angularjs的绑定事件
- AngularJS事件绑定的使用详解
- AngularJs事件绑定例子
- AngularJS-5-事件绑定
- 关于angularjs的下拉列表的绑定
- 关于JavaScript的事件绑定
- 关于javascript的事件绑定
- AngularJS 05(事件绑定)
- angularjs 绑定enter事件的两种方法
- AngularJS中,如何给动态生成的元素绑定事件
- Angularjs中使用指令绑定点击事件的方法
- 关于angularjs应该知道的知识点一双向绑定
- 关于js的事件绑定以及优缺点
- 关于iCheck 单选框的事件绑定
- 关于绑定事件
- 关于jquery绑定事件
- JavaScript关于事件绑定
- 关于点击click事件以及事件绑定的方式
- angular js 简单购物车(08)
- 第十三周项目2二叉树排序树中查找的路径
- XRecyclerView的多条目加载(banner+列表)
- CDH 系统优化之关闭透明大页面及设置swappiness
- Java 后台做图片压缩的两种方法
- 关于angularjs的绑定事件
- Swiper
- 深度学习中Batch size对训练效果的影响
- bzoj1066 [SCOI2007]蜥蜴(建图最大流)
- 关于 c/c++ 指针(详细解释)
- CentOS7部署vsftpd服务
- input file文件框 美化
- 哈哈哈哈哈哈哈哈哈哈哈哈
- 《剑指offer》刷题笔记(时间效率):连续子数组的最大和