Saturday, December 27, 2014

[jQuery] Cach reset form hoac reset value input tren form

Cach 1:

Doing this task with jQuery is really easy:
$('#FormID').each (function(){
  this.reset();
});
The thing is, that the code above iterates through each element of the form, and calls to the DOM “reset” JavaScript method. In fact, the “reset” function does not exist in jQuery.
It would be much more simple to do something like $(“#FormID”).reset(). Fortunately creating that function in jQuery only will take a minute of programming:
jQuery.fn.reset = function () {
  $(this).each (function() { this.reset(); });
}
Using the code above, reseting a form would be just one call (as desired):
$("#FormID").reset();

Cach 2:

<input type="button" onclick="this.form.reset();">
Cach 3:

function reset(){
    $('input[type=text]').val('');  
    $('#textarea').val(''); 
    $('input[type=select]').val('');
    $('input[type=radio]').val('');
    $('input[type=checkbox]').val('');  
}

[jQuery] Su dung javascript khi page load

src: http://learn.jquery.com/using-jquery-core/
Cach 1:
// A $( document ).ready() block.
$( document ).ready(function() {
console.log( "ready!" );
});

Cach 2:
// Shorthand for $( document ).ready()
$(function() {
console.log( "ready!" );
});

Cach 3:
// Passing a named function instead of an anonymous function.
function readyFn( jQuery ) {
// Code to run when the document is ready.
}
$( document ).ready( readyFn );
// or:
$( window ).load( readyFn );

VD:
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$( document ).ready(function() {
console.log( "document loaded" );
});
$( window ).load(function() {
console.log( "window loaded" );
});
</script>
</head>
<body>
<iframe src="http://techcrunch.com"></iframe>
</body>
</html>

Monday, December 1, 2014

Compare 2 DateTime

[C#]

using System;

public class Example
{
   public static void Main()
   {
      DateTime date1 = new DateTime(2009, 8, 1, 0, 0, 0);
      DateTime date2 = new DateTime(2009, 8, 1, 12, 0, 0);
      int result = DateTime.Compare(date1, date2);
      string relationship;

      if (result < 0)
         relationship = "is earlier than";
      else if (result == 0)
         relationship = "is the same time as";         
      else
         relationship = "is later than";

      Console.WriteLine("{0} {1} {2}", date1, relationship, date2);
   }
}
// The example displays the following output: 
//    8/1/2009 12:00:00 AM is earlier than 8/1/2009 12:00:00 PM

[VB]
Module Example
   Public Sub Main()
      Dim date1 As Date = #08/01/2009 12:00AM#
      Dim date2 As Date = #08/01/2009 12:00PM#
      Dim result As Integer = DateTime.Compare(date1, date2)
      Dim relationship As String 

      If result < 0 Then
         relationship = "is earlier than" 
      ElseIf result = 0 Then
         relationship = "is the same time as"          
      Else
         relationship = "is later than" 
      End If

      Console.WriteLine("{0} {1} {2}", date1, relationship, date2)
   End Sub 
End Module 
' The example displays the following output: 
'    8/1/2009 12:00:00 AM is earlier than 8/1/2009 12:00:00 PM

Compare 2 String fromA - toB

[JAVA]

/**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        String from_a = "$#ABDJAH000011";
        String to_b = "$#ABDJAH000010";
        int result = from_a.compareTo(to_b);
        if(result > 0){
            System.out.println("To_b must be after from_a in alphabets table");
        }
    }

var q = db.RandomTable as IQueryable;
if (checkBox.Checked)
{
    q = q.Where(/* condition */);
}