เปลี่ยนข้อความบนปุ่มเมื่อคลิก :
$(document).ready(function(){
$(".button").click(function(){
$(this).val("Some other text");
});
});
ใส่เครื่องหมายที่ลิงค์ ที่ลิงค์ไปยังเว็บอื่นด้วย Icon :
$('a').each(function(){
if(this.hostname != location.hostname){
$(this).append('<img src="external.png" />').attr('target','_blank');
}
});
สุ่มเปลี่ยนสีพื้นหลัง :
$(document).ready(function() {
changeColor();
});
function changeColor() {
var rndColors = ["#00FF00", "#CCCCCC", "#995499", "#FFFFFF", "#FF9900"];
var selColor = Math.floor(Math.random() * rndColors.length);
$('div').css("background-color", rndColors[selColor]);
setTimeout(changeColor, 1000);
}
เลื่อน Scrollbar ไปด้านบนแบบอนิเมชั่น :
$("a[href='#top']").click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
ตรวจสอบว่ามีไฟล์อยู่บน Server จริงๆ :
$('#btnSubmit).click(function () {
$.ajax({
url: $('#txtUrl').val(),
success: function (data) {
alert('File Exists!!!!!');
},
error: function (data) {
alert('File does not exist!!!!');
}
});});
ตรวจสอบว่า Internet สามารถใช้งานได้จริง :
function checkInternet() {
var status = navigator.onLine;
if (status) {
alert("Working");
} else {
alert("Not Working ");
}
}
ตัวอย่างการเรียกใช้:
<input type="button" value="Check Connection" onclick="checkInternet()" />
ป้องกันไม่ให้คลิกขวา :
$(function(){
$(document).on("contextmenu",function(e){
e.preventDefault();
});
});
ปรับปรุงล่าสุด: -/-