posts - 495,comments - 227,trackbacks - 0

          /*
          <--- --------------------------------------------------------------------------------------- ----
              
              Blog Entry:
              Creating jQuery Templates Plug-in Using Textarea Elements (Thanks Kurt Bonnet)
              
              Code Snippet:
              2
              
              Author:
              Ben Nadel / Kinky Solutions
              
              Link:
              http://www.bennadel.com/index.cfm?dax=blog:1393.view
              
              Date Posted:
              Nov 10, 2008 at 9:06 AM
              
          ---- --------------------------------------------------------------------------------------- --->
          */

          // Define the jQuery Template plugin. This takes a textarea
          // value and converts it into an jQuery DOM elements (outside
          // of the current DOM) and returns it. It takes only one
          // argument: the name-value pairs of the values to replace
          // into the template.
          jQuery.extend({template:function (strHTML, objValues) {
           
              // This will be our index variable for looping over the
              // values that were passed in.
              var strKey = "";
           
              // Check to make sure we have a value string. If this is
              // not the right kind of jQuery stack, the HTML string will
              // be null.
              if (strHTML) {
           
                  // Now that we have the proper value, we have to
                  // replace in the mapped values. Loop over each
                  // value that was passed in.
                  for (strKey in objValues) {
           
                      // Escape all the special values in the key so that
                      // it can be used in a regular expression.
                      strSafeKey = strKey.replace(new RegExp("([""[""]"".""+""*""{""}""("")""$""?""-])", "gi"), """$1");
           
                      // Replace the value.
                      strHTML = strHTML.replace(new RegExp("""{" + strSafeKey + """}", "gi"), objValues[strKey]);
                  }
           
                  // At this point, our HTML will have fully replaced
                  // values. Now, let's convert it into a jQuery DOM
                  // element and return it.
                  return (jQuery(strHTML));
              } else {
           
                  // Return empty jQuery stack.
                  return (jQuery([]));
              }
          }});

          posted on 2008-11-17 13:23 SIMONE 閱讀(775) 評論(0)  編輯  收藏 所屬分類: AJAXJavaScript
          主站蜘蛛池模板: 洞口县| 遂平县| 株洲县| 古田县| 呼玛县| 萨嘎县| 铁岭县| 崇左市| 乌鲁木齐县| 大关县| 靖远县| 青龙| 克山县| 汶上县| 巩义市| 东兴市| 江油市| 通山县| 密山市| 大名县| 嘉黎县| 那坡县| 柘荣县| 房山区| 余庆县| 松原市| 彝良县| 莲花县| 喜德县| 颍上县| 丽江市| 广东省| 财经| 安徽省| 鱼台县| 沅陵县| 同心县| 荃湾区| 翁牛特旗| 邵武市| 肇源县|