Monday, October 4, 2010

JQuery methods example & turorial

Javascript JQuery syntax, methods. try now


<html>
<body>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>

<div id="boroo" style="background-color:green;"><a>menu</a>
<span style="opacity:0;background-color:blue;width:200px;position:relative;">popup menu</span>
</div>

<script type="text/javascript">
$("#boroo").mousedown(function(event) {
    if(event.button == 2){
        $("#boroo span").animate({opacity:1},"slow");
    }
    else $("#boroo span").animate({opacity:0},"slow");
});

$(document).ready(function(){       
        $(document).bind("contextmenu",function(e){
            return false;
        });

    $("#boroo span").focusout(function(){
        $(this).css("display","none");
    }).css("left",-2*$($("#boroo").contents().get(0)).width()).css("top",$("#boroo").css("height"));
});
</script>
//~=hooson zaitai
//!=tentsuu bish
//^=ehlel ni tentsuu
//$=togsgol ni tentsuu
//*=aguulagdaj baival
//|=ehlel-zuraas orson

<div id="abc" style="height:40px; background-color:blue;">
<a href="#">baldskf lakdj;falkdsj;lfka jd;klja;dlks jal;d </a>
</div>

<form name="form1">
  <input id="target" type="text" value="Field 1" />
  <input type="text" value="Field 2" />
  <input type="checkbox" name="isactive" id="isactive"/>
</form>

<div id="other">
  Trigger the handler
</div>

<select name="sweets" multiple="multiple">
    <option>Chocolate</option>
    <option selected="selected">Candy</option>
    <option>Taffy</option>
    <option selected="selected">Caramel</option>
    <option>Fudge</option>
    <option>Cookie</option>
  </select>

<script type="text/javascript">

$(document).ready(function() {
    try{
        $("div#abc a").css("color","white");
        $("div#abc a").attr("href","?name=boroo");
        $("div").click(function(){ $(this).children().focus(); });
        $("div").focusout(function() { alert($(this).get(0).tagName); });
    }catch(ex){
        alert(ex);
    }
    //alert("ready");
});
//$(window).load( function () { alert("Hello now!"); } );
//$(window).unload( function () { alert("Bye now!"); } );

//appendTo(document.body);
$("div#other").append("<p> my name is boroo </p>");

//alert($("input:checkbox[name='isactive']").get(0).id);
//alert($("input:checkbox").filter(":not(:checked)").get(0).id);

//alert($("input:checkbox").is(":checked"));

 $("select").change(function () {
    var str = "";
              $("select option:selected").each(function (index) {   
                    str += $(this).text() + " ";
                  });
    $(document).data("str",str);//("#abc")
        }).change();

$(document.body).delegate("div#abc a", "mouseover", function(){
    $(this).fadeOut("slow");
    alert($(document).data("str"));
});

jQuery.each(jQuery.browser, function(i) {
   if($.browser.msie){
      //alert("Internet explore");
   }else{
      //alert("Others"+jQuery.browser.version);
   }
 });

function listX() {
        var xtn = "id";
        var xt =  "id="+1;
        $.ajax({
            url:'${pageContext.request.contextPath}/admin/core/xdata/ListXdatarow/',
            type:'post',
            data:xt,
            //beforeSend:,
            dataType:'html',
            success:function(data){
                $("#listShowTarget").html(data);
            }
        });
    }
</script>

<table id="table1">
<tr><td>TD #00</td><td>TD #01</td><td>TD #02</td></tr>
</table>
<table id="table2">
<tr><td>
<input type="text" maxlength="30" value="sadfasdf asdfasd" size="100" style="width:8px;"></td><td>TD #1</td><td>TD #2</td></tr>
<tr><td>TD #3</td><td>TD #4</td><td>TD #5</td></tr>
<tr><td>TD #6</td><td>TD #7</td><td>TD #8</td></tr>
</table>
<script>
//$('#table2 tr:eq(1) td').slice(0,1).css("background-color","red");
//var td = $("table[id='table2'] tr td:eq(8)");
//alert($("#table2 tr td").index(td));
//$("tr:eq(1)").css("color", "red");
//$("td:gt(7)").css("color", "red");
//:eq(), :lt(), :gt(), tr:even, tr:odd
</script>

<div class="container">
  <h2>Greetings</h2>
  <div class="inner">Hello</div>
  <div class="inner">Goodbye</div>
</div>
<script>
//$('.inner').after('<p>Test</p>').after('<p>Test</p>');
</script>

<div id="boroo" style="background-color:green;">menu<span style="display:none;background-color:blue;width:200px;position:relative;">popup menu</span></div>
<script>
$("#boroo").mousedown(function(event) {
//  alert("Current mouse position: " + event.pageX + ", " + event.pageY + " : " + event.button);
});
$(document).ready(function(){
    $(document).bind("contextmenu",function(e){
        return false;
    });
});
</script>
               
//zovhon songoson elements iin childuud children() tai tostei command 
<ul class="topnav">
    <li>Item 1</li>
    <li>Item 2 
        <ul><li>Nested item 1</li><li>Nested item 2</li><li>Nested item 3</li></ul>
       </li>
    <li>Item 3</li>
</ul>
<script>$("ul.topnav > li").css("border", "3px double red");</script>

</body>
</html>

No comments: