2015年6月14日日曜日

jQuery JavaScript 対比メモ

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script src="./jquery-2.1.4.js" type="text/javascript"> </script>
    <script>
        $(function () {

//$(document).on('click', 'div', function() {
// $(this).css('background', 'red');
//});
var targetInput = ':text, :password, textarea';
$(targetInput).on('focus' , function(){
                $(this).css('background-color','Pink');
});

$(targetInput).on('blur', function(){
                $(this).css('background-color','White');
});

$(targetInput).blur(function(){
if ($(this).find('.jFocus')) {
$(this).removeClass('jFocus');
}
});
$('input:focus').css('background-color', 'Pink')

$('div').css('background-color', 'Aqua');

            $('input[name="btn1"]').on('click',function(){
//alert('AAA');
var regEx = /^[0-9]{1,2}/;
var txt = $('input[name="txt1"]').val();

if(txt.match(regEx)){
//alert('matched');
//document.getElementById('Result').innerText='<b>matched</b>'
//document.getElementById('Result').innerHTML='<b>matched</b>'
//$('#Result').text('Matched');
$('#Result').html('<b>Matched</b>');

//$('#Result').
}else{
//alert('Not matched');
//document.getElementById('Result').innerHTML='<b>Not matched</b>'

}
});
//$('#Buttion1').click(function (){
            //    alert('hello');
            //});
        });

function button_clicked(){
//alert("abcde");
var regEx = /^[0-9]{1,2}/;
var txt = document.getElementById('Text1').value;
if(txt.match(regEx)){
//alert('matched');
//document.getElementById('Result').innerText='<b>matched</b>'
document.getElementById('Result').innerHTML='<b>matched</b>'
}else{
//alert('Not matched');
document.getElementById('Result').innerHTML='<b>Not matched</b>'

}
};
    </script>
 
    <title></title>
</head>
<body>
    <div>
        <input id="Text1" type="text" name="txt1" />
    </div>
    <div>
        <input id="Button1" name="btn1" type="button" value="button1" />
<input id="Button2" type="button" value="button2" onClick="button_clicked();"/>
</div>
    <div id="Result" >
     
</div>

</body>
</html>

0 件のコメント:

コメントを投稿