Jack @ ASP.NET

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries Tagged ‘lt’

Manage a checkbox via jQuery

the checkBox in html should be

<input type="checkbox" class="myCheckBox" />

Bind a click event to a checkbox

$(".myCheckBox").click(myCheckboxEvent);

The click event like this

function myCheckboxEvent() {
    alert($(this).is(':checked')); // alert the checked value
}

You can see, it is quite easy to ‘get’ the checkbox sender via jQuery -‘this’

Convert RGB Color To Hex With JavaScript

   1: function colorToHex(color) {

   2:     if (color.substr(0, 1) === '#') {

   3:         return color;

   4:     }

   5:     var digits = /(.*?)rgb\((\d+), (\d+), (\d+)\)/.exec(color);

   6:     

   7:     var red = parseInt(digits[2]);

   8:     var green = parseInt(digits[3]);

   9:     var blue = parseInt(digits[4]);

  10:     

  11:     var rgb = blue | (green << 8) | (red << 16);

  12:     return digits[1] + '#' + rgb.toString(16);

  13: };

Happy new year!

C# Code Snippet: List.ForEach method

Do you ever use the List(T).ForEach Method in C#, if never, you’d better read this.

The syntax is :
public void ForEach(Action<T> action)

   1: static void Main()

   2: {

   3:     List<long> myList = new List<long>();

   4:     foreach (string item in "269, 361, 347, 355, 352, 346, 351, 354".Split(','))

   5:     {

   6:         myList.Add(long.Parse(item.Trim()));

   7:     }

   8:     myList.ForEach(FA);

   9: }

  10:  

  11: static void FA(long num)

  12: {

  13:     Console.WriteLine(num);

  14: }

Is that cool? It gives lots of convenience in coding!