var arr = [1,2,3];
arr.push(4); //Adds new elements to the end of an array, and returns the new length, result arr = [1,2,3,4];
arr.pop(); //Removes the last element of an array, and returns that element, result arr = [1,2];
arr.length = 0; // remove all element
function setDropDownList(elementRef, valueToSetTo)
{
var isFound = false;
for (var i = 0; i < elementRef.options.length; i++)
{
if (elementRef.options[i].value == valueToSetTo)
{
[...]
function StringFormat(str)
{
for (i = 1; i < arguments.length; i++)
{
str = str.replace(’{’ + (i – 1) + ‘}’, arguments[i]);
}
return str;
}
example using:
var greeting = format(‘Hello {0} & {1} ‘, ‘John’, ‘Jane’);
ref: http://xneuron.wordpress.com/2006/09/29/stringformat-in-javascript-as-in-c/
String.prototype.trim = function()
{ return (this.replace(/^[\s\xA0]+/, “”).replace(/[\s\xA0]+$/, “”)) }
String.prototype.endsWith = function(str)
{ return (this.match(str + “$”) == str) }
String.prototype.startsWith = function(str)
{ return (this.match(”^” + str) == str) }
function getClientIdByEndsWith(strid)
{
var count = document.forms[0];
var i = 0;
var eleName;
var found = false;
[...]
+
Compatible with all major browsers: IE6+, Firefox, Opera, Safari and Chrome
ref: http://getfirebug.com/releases/lite/chrome/
1. VS 2005 – create new website with ASP.NET Ajax-Enabled Website , then create WebService.asmx
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService] // <== [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}[WebMethod]
public string HelloWorld() [...]
<!– Paste this code into an external JavaScript file named: dateFormat.js –>
/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Oded Arbel :: http://geek.co.il/wp/ */
/**
* Extension of the JavaScript internal Date object to allow various formatting of
* date/time values.
* This implementation was designed to be compliant with the [...]
add this script in html page
<script type=’text/javascript’
src=’http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js’></script>
then run
——————–
When you sort an array in Javascript the array gets sorted into dictionary order. This means that ‘A’ is less than ‘a’ and gets sorted [...]
ในภาษาโปรแกรมมิ่งที่มีคนใช้กันมากๆเกือบทุกตัว จะต้องมีโอเปอเรเตอร์ในการดำเนินการทางตรรกะแบบลัด ซึ่งมีชื่อว่า Short-Circuit Operator ซึ่งเราสามารถที่จะใช้เจ้าตัว Short-Circuit Operator ให้เป็นประโยชน์ได้
ทำได้อย่างไร?
กฏของ Short-Circuit Operator อยู่บนกฏพื้นฐานของ && และ || นั้นคือ
สำหรับ && แล้วถ้ามีตัวใดตัวหนึ่งในนิพจน์เป็นเท็จค่าของนิพจน์ && จะเป็นเท็จทันที
ตัวอย่างที่แสดงได้ดังต่อไปนี้
Code Sample
bool p = false;
bool q = true;
if (p && q) // ที่บรรทัดนี้โปรแกรมสามารถสรุปได้ทันที่ว่าเงื่อนไขนี้เป็นเท็จ
; // โดยไม่ต้อง evaluate(คำนวณ)ค่าของ q แต่กลับกันหาก
// p เป็น true q ต้องถูก evaluate ค่า
ตัวอย่างในสถานการณ์จริงเช่นเราต้องการ เรียกใช้งาน Method ที่อยู่ใน class
แต่ตัวแปรที่ใช้เก็บ instance ของคลาสนั้น อาจมีค่าเป็น null ได้
เพื่อหลีกเลี่ยง NullException เราจึงต้อง Check ค่าของตัวแปรว่ามีค่าเป็น Null [...]