目前分類:JS (8)

瀏覽方式: 標題列表 簡短摘要

JS OBJECT LOOP

MAP:

for (const [key, value] of prodObjMap) {
  console.log(key, value)
}

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

input 只能輸數字和逗號

<input  type="text" placeholder="EX:12345,23456" onchange="this.value=this.value.replace(/[^0-9,]+/g, '');" />

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

 use JSTL 

model.addAttribute("listData", listData);
<c:forEach items="${listData}" var="listData">
    ${listData.name}
</c:forEach>

 

 use JS 

model.addAttribute("listData", new Gson().toJson(listData));
var listData = JSON.parse('${listData}');
$.each(listData, function(i){
    listData[i].name;
});

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

ajax的return要特別注意寫法,用變數接回再傳

$(function () {
    var console.log(testGetResult());   // 抓不到預期的boolean , show undefined
        var console.log(testGetResult2());  // show true or false
});

function testGetResult() {
        $.ajax({
        url: '/getData.do',
        type: 'get',
                async: false,
                success: function (res) {
            return true;
        },
        error: function (res) {
            return false;
        }
    });
}

function testGetResult2() {
        var rtn;
    $.ajax({
        url: '/getData.do',
        type: 'get',
                async: false,
                success: function (res) {
            rtn = true;
        },
        error: function (res) {
            rtn = false;
        }
    });
        return rtn;
}

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

var jsonObj=[]; 
var tempPrdList=[];

tempPrdList.push("12");
tempPrdList.push("34");
tempPrdList.push("56");

for (i = 0, j = tempPrdList.length; i < j; i++) {
  var obj = new Object;
  obj.id = tempPrdList[i];  //key=id
  jsonObj.push(obj);
}

console.log(JSON.stringify(jsonObj));  //[{"id":"12"},{"id":"34"},{"id":"56"}]

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

頁面有時候要增埋監聽事件,又怕被綁在物件上的事件影響時,有以下順序可以作為參考切入點

EX:
1. 連結裡埋一個onclick事件
2. 連結設為 https://www.google.com.tw/ 
3. 再分別設3個監聽.on()事件

<a id="testID" onclick="alert('tagOnclick');" href="https://www.google.com.tw/">
For test
</a>
$("#testID").on('click', function(event){
    alert("1");
});

$("#testID").on('click', function(event){
    alert("2");
});

$("#testID").on('click', function(event){
    alert("3");
});

 

RESULT:

alert('tagOnclick');
alert('1');
alert('2);
alert('3');
location to https://www.google.com.tw/

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

畫面不可滑動(顯示目前畫面),如有ScrollBar ,則鎖住使用 

測試可用版本: IE8+,FIREFOX,CHROME

測試不可用版本:IE7

CSS設定

html.noscroll {
    position: fixed; 
    overflow-y: scroll;

文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()

image

checkbox

  • 有被選中的obj

$(':checkbox[name=checkboxObjName]:checked')

 


文章標籤

咪卡恰比 發表在 痞客邦 留言(0) 人氣()