Monday, September 17, 2012

jQuery : การเรียกใช้ jQuery

หลังจากที่เรา Download file jquery มาแล้ว
จะได้ ไฟล์ ดูรูปนะครับ
ในที่นี้เป็น Version 1.8.1 นะครับ



ให้เราสร้าง ไฟล์ขึ้นมา 1 ไฟล์นะครับ ในที่นี้จะสร้าง ไฟล์ เป็น file1.html นะครับ


<!--file1.html-->
<meta charset='utf-8'>

<script type='text/javascript' src='jquery-1.8.1.min.js'></script>

<script type='text/javascript'>
$(function(){
alert('test');
});
</script>

หลังจากนั้นเราลองเรียกไฟล์ที่เราเขียนขึ้นนะครับ มันจะแสดง alert box ว่า test
แสดงว่าใช้งาน jQuery ได้แล้วครับ

อธิบายนะครับ
<meta charset='utf-8'>
 -การ encode page นั้นๆ เป็น utf-8

<script type='text/javascript' src='jquery-1.8.1.min.js'></script>
 -การเรียกใช้ jquery ไฟล์


 -$(function(){});  หมายถึงเมื่อ page โหลดจะโหลดคำสั่งที่อยู่ภายใต้ {} โดยเราสามารถเขียน คำสั่งแบบ jquery หรือ javascript ได้เลย


ถ้าไม่เข้าใจตรงไหนสอบถามได้นะครับ

BY N1B




JQuery : เริ่มต้นกับ JQuery

JQuery : เริ่มต้นกับ JQuery

Website สำหรับ Download ตัว Framework

http://www.jquery.com/



ให้เรา Download มานะครับโดยกดที่ Download (jQuery);

จะได้เป็น .js มานะครับผม


บทต่อไปเราจะมารู้จักวิธีการใช้งานนะครับผม

BY N1B



Friday, September 14, 2012

PHP : Create font for my web.(มาสร้าง Font ใช้บน Website ของเรากัน)

มาสร้าง Font ใช้บน Website ของเรากัน



http://www.fontsquirrel.com/fontface/generator





หลังจากนั้นให้ สร้าง ไฟล์ ชื่ออะไรก็ได้ .html
แล้วใส่ code ดังนี้

<link href="stylesheet.css" rel="stylesheet" type="text/css"></link>
<style type="text/css">
   body{
    font-family: 'db_king84regular';
    font-size:50px;
   }
</style>
<body>
  บทความดีๆ ยังมีอีกเยอะ ขอให้ติดตามกันต่อไปนะครับ
</body>

Result              

BY N1B



PHP : Create Class INPUT TAG

<?
class Input{
var $json;
var $prop;
var $attr;
function Input(){}
function setProp($json='',$oldJson=''){
$this->json=$json;
if($oldJson!=''){
$merge=array_merge(json_decode($oldJson,true),json_decode($this->json,true));
$this->json=json_encode($merge);
}
$this->prop=json_decode($this->json,true);
$this->attr='';
foreach($this->prop as $key1=>$value1){
$this->attr.=strtoupper($key1).'=';
if(is_array($value1)){
$style='';
foreach($value1 as $key=>$value){
$style.=$key.':'.$value.';';
}
$this->attr.='\''.$style.'\' ';
}
else{$this->attr.='\''.$value1.'\' ';}
}
}
function getProp(){return $this->json;}
function setVisible($boolean=true){return '<INPUT '.$this->attr.'/>';}
}
$txt=new Input();
$txt->setProp('{
"type":"password",
"name":"txtUsername",
"id":"txtUsername",
"style":{"height":"30px","font-weight":"bold","border":"1px solid #0099FF"}
}');
print $txt->setVisible(true);
?>
Result              




มีตรงไหนสงสัยถามได้เลยนะครับ


BY N1B

Tuesday, August 28, 2012

PHP : Convert Array To String(การแปลงจากตัวแปรชุดเป็นข้อความ)

PHP : Convert Array To String(การแปลงจากตัวแปรชุดเป็นข้อความ)


<?
   $arr=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
   $str=implode(',',$arr);
   print $str;

?>

Result (ผลลัพธ์)
A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z




BY N1B

Monday, August 27, 2012

JQuery : Multiple jQuery Get Scripts


/* enhance $.getSctipt to handle mutiple scripts */
var getScript = jQuery.getScript;
jQuery.getScript = function( resources, callback ) {

    var // reference declaration & localization
    length = resources.length,
    handler = function() { counter++; },
    deferreds = [],
    counter = 0,
    idx = 0;

    for ( ; idx < length; idx++ ) {
        deferreds.push(
            getScript( resources[ idx ], handler )
        );
    }

    jQuery.when.apply( null, deferreds ).then(function() {
        callback && callback();
    });
};

$.getScript(['script1.js','script2.js','script3.js'], function() {
    //do something after all scripts have loaded
});

//or seperate into an array to include

var scripts = ['script1.js','script2.js','script3.js'];
$.getScript(scripts, function(data, textStatus) {
    //do something after all scripts have loaded
});

Tuesday, August 21, 2012

PHP : Get Client IP


ฟังชั่นนี้เป็นการแสดงค่า IP ของเครื่องคอมพิวเตอร์ที่ เข้ามาดูเว็บเรานะครับ

function getClientIP(){
   if(!empty($_SERVER['HTTP_CLIENT_IP'])){
     $ip=$_SERVER['HTTP_CLIENT_IP'];
   }
   else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
     $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
   }
   else {
     $ip=$_SERVER['REMOTE_ADDR'];
   }
   return $ip;
}

print getClientIP();


BY N1B