继续
1.按钮点击颜色固定
$(".productbtn").click(function() {
$(".productbtn").removeClass('active')
$(this).addClass('active')
})
2.删除git分支
git push origin --delete 分支名称
3.git添加tag,并push到远程仓库
git tag -a v0.1.0 -m "0.1.0版本"
git push origin v0.1.0
4.替换字符串中一部分为‘*’
var str = "123456789"
var re = /([\s\S][2]([\s\S]{3}))/
console.log(str.replace(re,"$1******"))
5.git为单个仓库的用户名邮箱配置
当再单个仓库中设置了用户名和邮箱,就会代替全局的用户名和邮箱
$ git config user.name "用户名"
$ git config user.email "邮箱"
6.jquery将文字超出部分变成省略号
$(function() {
$('[data-toggle="tooltip"]').tooltip()
var arr = $('.description')
console.log(arr)
for(var i =0 , len = arr.length;i < len;i++){
var j = arr[i].innerHTML
console.log(j+" "+j.length)
if (j.length>30) {
j = j.substr(0, 30) + "..."
}
console.log("转换后:"+j)
$('.description')[i].innerHTML = j
}
});
7.bootstrap按钮将值传到模态框
<button data-toggle="modal" data-target="#del" ng-click="setId(x.id)">删除</button>
将场景id存入变量
$scope.setId = function(x) {
$log.log(x)
$scope.sceneId = x
}
模态框
<div class="modal fade sceneManageDelPop" tabindex="-1" role="dialog" id="del">
<div class="modal-dialog " role="document">
<div class="modal-content">
<header>
<span>删除场景提示</span>
</header>
<section>
![](images/equipmentDetails/u3613.png)
<p id="p1">确认删除此场景?</p>
<p id="p2">删除后,已启用此场景的设备将失去联动。请注意,场景不可恢复,需重新添加。</p>
</section>
<footer>
<button type="button" class="ok" ng-click="deleteScene(sceneId)" data-dismiss="modal">确认</button>
<button type="button" class="cancel" data-dismiss="modal">关闭</button>
</footer>
</div>
</div>
</div>
8.省市县三级联动
1)清空select
select.length = 0
2)核心代码
/数组转成对象
function arrToObject(arr) {
var paramobj = {};
arr.forEach(function(v, i) {
paramobj[v.name] = v; //特征值,这里使用name
})
return paramobj
}
var somedata = arrToObject(provinceList)
//遍历省
var provincearr = []
for (var i = 0, len = provinceList.length; i < len; i++) {
provincearr.push(provinceList[i].name)
}
var province = document.getElementById('province')
var city = document.getElementById('city')
var area = document.getElementById('area')
/**显示到下拉列表
* @param x 下拉
* @param arr 数组
*/
function pushToOption(x, arr) {
for (var i = 0, len = arr.length; i < len; i++) {
x.options[i] = new Option(arr[i], arr[i])
}
}
pushToOption(province, provincearr)
// 省下拉改变触发函数
var cityobj = {}
function provincesel(x) {
city.length = 0
area.length = 0
//市辖区和县的选择
var citylen = somedata[x].cityList.length
var cityarr = []
for (var i = 0; i < citylen; i++) {
cityarr[i] = somedata[x].cityList[i].name
}
pushToOption(city, cityarr)
cityobj = arrToObject(somedata[x].cityList)
}
//市辖区下拉改变触发函数
function citysel(x) {
area.length = 0
pushToOption(area, cityobj[x].areaList)
}
9.ubuntu安装nodejs
1)nvm
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
2)安装nodejs
nvm install 8.4.0
10.ng将数字转变成相应长度的数组
$scope.scannum = Array.from({ length: 你的数字 }, (n, i) => i);
11.ng点击按钮增加div
<ul>
<li ng-repeat="item in list"><a href="">test</a></li>
</ul>
会报错
Duplicates
in a repeater are not allowed. Use ‘track by‘ expression to specify
unique keys. Repeater: c in shopCount, Duplicate key:
undefined:undefined
将ng-repeat中内容改为
ng-repeat="item in list track by $index"
即可解决
12.ng,directive报错:Error: [$compile:tplrt] Template for directive 'editScene' must have exactly one root element.
replace属性为true时,会替换directive指向的元素。为false时,将directive的内容作为子元素插入到directive指向的元素。默认的replace为false
replace为true时,template就只能有一个根元素
例如:
如果像下面,有多个根元素向下面,有多个根元素,且replace为true,那么就会报错
解决方式就是将replace改成false,或者删掉
13.ng过滤器,过滤时间
app.filter('currentDate', function(){
return function(text){
var date = new Date(text).toLocaleString()
return date
}
})