繼續(xù)
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("轉(zhuǎn)換后:"+j)
$('.description')[i].innerHTML = j
}
});
7.bootstrap按鈕將值傳到模態(tài)框
<button data-toggle="modal" data-target="#del" ng-click="setId(x.id)">刪除</button>
將場景id存入變量
$scope.setId = function(x) {
$log.log(x)
$scope.sceneId = x
}
模態(tài)框
<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>

<p id="p1">確認刪除此場景?</p>
<p id="p2">刪除后,已啟用此場景的設備將失去聯(lián)動。請注意,場景不可恢復,需重新添加。</p>
</section>
<footer>
<button type="button" class="ok" ng-click="deleteScene(sceneId)" data-dismiss="modal">確認</button>
<button type="button" class="cancel" data-dismiss="modal">關(guān)閉</button>
</footer>
</div>
</div>
</div>
8.省市縣三級聯(lián)動
1)清空select
select.length = 0
2)核心代碼
/數(shù)組轉(zhuǎn)成對象
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 數(shù)組
*/
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)
// 省下拉改變觸發(fā)函數(shù)
var cityobj = {}
function provincesel(x) {
city.length = 0
area.length = 0
//市轄區(qū)和縣的選擇
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)
}
//市轄區(qū)下拉改變觸發(fā)函數(shù)
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將數(shù)字轉(zhuǎn)變成相應長度的數(shù)組
$scope.scannum = Array.from({ length: 你的數(shù)字 }, (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中內(nèi)容改為
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的內(nèi)容作為子元素插入到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
}
})