Nov 09

Kim·2020년 11월 9일
0

forEach <-배열.객체랑 같이
ar=[1,2,3,4]
ar.forEach(function(a1){
console.log(a1);
}

Use $ instead of jQuery

jquery
$.each(ar,function(index,value){
console.log(value);
});

('table tr').each(function(ndx,str){ str=(this).find('td:eq(0)').text();
console.log(str);
});

ar=[1,2,3,4]
.inArray(3,ar);//n=2.inArray(3,ar); // n=2.inArray(7,ar); // n=-1

$.isArray(7,ar) // n=false

isNaN(is Not a Number) 숫자가 아닌 것을 골라낸다
a='24';
b=isNaN(a); // b=false; //숫자이다

a='a2';
b=isNaN(a); // b=true; //숫자가 아니다 (사용할 때 헷갈리지 않게 주의)

$.isNumeric(a)

a가 숫자로만 이루어져 있는가?
'a2' >>> false
24 >>> true

jQuery.now()

var dt = new Date();
var dt = $.now();

$.ajax({method:get/post...})

calling a method : get or post

$.post()

$.get()

ready

$(document) is an object

$(document)
.ready(function(){
 // As webpage loading ends, execute this function first. (reset part)

📌 practice

특정 tr 위에 마우스를 대면 빨간색이 되고 다른 tr에 마우스가 올라가면 원래 색으로 돌아오는 코드를 짜라

  • Code 1.

  • Code 2.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <table border=1>
    </table><br><br>
    <table>
        <tr>
            <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
        </tr>
    </table>
</body>
<script src="http://code.jquery.com/jquery-3.5.0.js">
</script>
<script language="javascript">
    var ndx=-1;
    var bgColor=null;
$(document)
.ready(function(){
    $('table tr:even').css('background-color','yellow');
    $('table tr:odd').css('background-color','blue');
})
.on('mouseover','tr',function(){
    if(ndx>-1){
        $('table tr:eq('+ndx+')').css('background-color',bgColor)
        //restore
    }
    
    ndx=$(this).index(); //current index
    bgColor=$(this).css('background-color'); //current color
    $(this).css('background-color','red');
})
</script>
</html>

$.trim()

remove blanks in String

key ~~

.length

THe number of elements in jQuery
$('select').length how many select in this document

multiple attribute selector

$('input[type=rado][name=gender]').is(':checked')

without coma

multiple selector

.on('click','div',function(){
})
.on('click','table',function(){
})
.on('click','#female',function(){
})

== .on('click','div, table, #female',function(){
})

.next()

immediately following sibeling

//table
//tr td 123 /td td 456 /td

opposite to .prev()

parents, position (좌표구하기), prepend, remove

replaceWith()

$(x).replaceWith(y) >>> replace x to y (change the whole tag)

  • change property
    $(x).prop('z', 'y') >>> change property in x (change only property)

.resize(), .scroll()

show()

oppoiste to hide()

.trigger() ❤

ajax

0개의 댓글