簡體   English   中英

從jQuery轉換為原型

[英]Converting from jquery to prototype

我有以下要轉換為原型的jQuery。 我在使其無法正常工作時遇到了一些實際麻煩,因為我不知道如何在Rails應用程序中正確對其進行初始化。

$(document).ready(function(){
    /*** Search label  ***/
    htmlinput = $("input#panel-search").val() /* picks the inital value of the input (in the html) */
    $("input#panel-search").css('color','#aeaeae').css('font-style','italic').css('font-weight','bold');
    $("input#panel-search").focus(function(){ /* on focus.. */
        curinput = $(this).val() /* picks the -current- value */
        if(curinput == htmlinput){ /* if the current value corrispond to the initial value (htmlinput var) */
            $(this).val(''); /* empty the input */
            $(this).css('color','black').css('font-style', 'normal').css('font-weight','normal');
        }
    });
    $("input#panel-search").blur(function(){ /* on blur */
        curinput = $(this).val();
        if(curinput == ''){ /* if the current value is null .. */
            $(this).css('color','#aeaeae').css('font-style','italic').css('font-weight','bold');
            $(this).val(htmlinput); /* sets the value with its inital value (htmlinput var) */
        }
    })    

    /* Main Navigation hover effect */
    $("ul#navigation li:not('.current'), ul#navigation li:not('highlighted')").hover(
      function () {
        $(this).addClass("hover");
      }, 
      function () {
        $(this).removeClass("hover");
      }
    );

    /* Right Menu hover effect */
    $("ul#fast-links li:not('.current')").hover(
      function () {
        $(this).addClass("current");
      }, 
      function () {
        $(this).removeClass("current");
      }
    );
});

任何幫助將非常感激。

Event.observe(document, 'ready', function () {
    /* pick the inital value of the input (in the html) */
    var $htmlinput = $('input#panel-search');
    var originalValue = $htmlinput.getValue();
    /* Set styles */
    $htmlinput.setStyle({
        color: '#aeaeae',
        'font-weight': 'bold',
        'font-style': 'italic'
    });
    /* on focus.. */
    $htmlinput.observe('focus', function () {
        /* pick the -current- value */
        var $input = $(this);
        /* Clear the input element if the value hasn't changed from
           the original value */
        if($input.getValue() === originalValue) {
           $input.clear();
           $input.setStyle({
              'color': 'black',
              'font-style': 'normal',
              'font-weight','normal'
           });
        }
    });
    $htmlinput.observe('blur', function () {
       /* CHANGE THIS SIMILAR TO ABOVE */
       /* INSIDE IF-CASE */
       $(this).setValue(originalValue);
    });
}
/* Main Navigation hover effect */
/* Prototype doesn't have the fancy :not pseudo-selector, so iterate over
 * all li:s, and filter out the once that shouldn't be affected */
$('ul#navigation li').each(function (el) {
   var isCurrent = el.hasClassName('current'),
       isHighlighted = el.hasClassName('highlighted');
   if(isCurrent || isHighlighted) {
      return;
   }
   el.observe('mouseenter', function () {
      $(this).addClassName('hover');
   });
   el.observe('mouseleave', function () {
      $(this).removeClassName('hover');
   });
});
/* TRANSLATE THE RIGHT NAVIGATION IN THE SAME WAY */

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM