-->
ラベル css の投稿を表示しています。 すべての投稿を表示
ラベル css の投稿を表示しています。 すべての投稿を表示

2011-10-13

jqueryのbind以外でclickに引数をもたせる

参考URL。
http://www.tinybeans.net/blog/2009/02/19-134819.html
http://semooh.jp/jquery/api/events/bind/type,+%5Bdata%5D,+fn/

jqueryのbind以外でclickに引数をもたせる。
$(xxx).click((function(key){return function(){
    ...
};})(key));
追記: ループの中で使うと遅くなりそうなのでbind("click" ...)の方が良いです。

例。


ソース。
<style type="text/css">
<!--
body #click-test-ap8cljwu, body #click-test-ap8cljwu * {
  background-color: white;
  border-width: 0;
  color: black;
  font-family: "MS ゴシック","Osaka-mono",monospace;
  font-size: 14px;
  font-style: normal;
  font-variant: normal;
  font-weight: normal;
  letter-spacing: 0;
  line-height: 14px;
  margin: 0;
  padding: 0;
  text-align: center;
  text-indent: 0;
  text-transform: none;
  white-space: nowrap;
  word-spacing: 0;
  word-wrap: normal;
}
body #click-test-ap8cljwu {
  margin: 0 auto;
  width: 336px;
}
body #click-test-ap8cljwu .click-test-ap8cljwu-list {
  height: 21px;
  margin-left: 7px;
  text-align: left;
}
body #click-test-ap8cljwu .click-test-ap8cljwu-list ul {
  background-color: transparent;
  position: absolute;
}
body #click-test-ap8cljwu .click-test-ap8cljwu-list li {
  display: block;
  float: left;
  margin-right: 7px;
  _width: 1px;
}
body #click-test-ap8cljwu .click-test-ap8cljwu-list a {
  background-color: #D3D3D3;
  border: 1px solid black;
  cursor: pointer;
  display: block;
  height: 14px;
  line-height: 14px;
  padding: 3px 7px;
}
body #click-test-ap8cljwu .click-test-ap8cljwu-list a.selected {
  background-color: white;
  border: 1px solid black;
  border-bottom-color: white;
}
body #click-test-ap8cljwu .click-test-ap8cljwu-result {
  border: 1px solid black;
  clear: both;
  height: 280px;
  overflow: auto;
  padding: 7px;
  text-align: left;
}
body #click-test-ap8cljwu .click-test-ap8cljwu-list ul {
  border-bottom-width: 0;
  list-style-type: none;
  margin: 0;
  padding: 0;
}
body #click-test-ap8cljwu .click-test-ap8cljwu-list ul li {
  border-top-width: 0;
  float: left;
  line-height: 14px;
  margin-top: 0;
  padding: 0;
}
-->
</style>
<div id="click-test-ap8cljwu"></div>
<script type="text/javascript">
//<![CDATA[<!--
try{(function(){
    var key, aElem, liElem,
    id = "click-test-ap8cljwu",
    list = {
        "one": ["ホーム", "1番", "ファースト"],
        "two": ["お知らせ", "2番", "セカンド"],
        "three": ["お問い合せ", "3番", "サード"]
    },
    listElem = document.createElement("div"),
    ulElem = document.createElement("ul"),
    resultElem = document.createElement("div");
    $(listElem).addClass(id + "-list");
    $(resultElem).addClass(id + "-result");
    $("#" + id).append(listElem);
    $(listElem).append(ulElem);
    $("#" + id).append(resultElem);
    for (key in list)
    {
        liElem = document.createElement("li");
        aElem = document.createElement("a");
        $(liElem).append(aElem);
        $(aElem).text(list[key][0]);
        $(aElem).click((function(key){return function(){
            var x;
            $("#" + id + " ." + id + "-list a").removeClass("selected");
            $(resultElem).text("");
            $(resultElem).append("key = " + key + "<" + "br/>");
            for (x = 0; x < list[key].length; x++)
            {
                $(this).addClass("selected");
                $(resultElem).append("list[" + key + "][" + x + "] = " + list[key][x] + "<" + "br/>");
            }
        };})(key));
        $(ulElem).append(liElem);
        $("#" + id + " ." + id + "-list a").each(function(){
            $(this).click();
            return false;
        });
    }
})();}catch(e){document.write("<"+"pre>Error: " + e + "<"+"/pre>");}
//-->]]>
</script>

2010-05-20

検索フォームの入力エリアとボタンを繋げるcssの例

bloggerで「このブログを検索」をサイバーに追加した場合の
検索フォームの入力エリアとボタンを繋げるcssの例です。
地味になります。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="ja" xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
 <head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
  <meta content="text/css" http-equiv="Content-Style-Type" />
  <meta content="text/javascript" http-equiv="Content-Script-Type" />
  <style type="text/css">
   <!--

body {
  background       :none repeat scroll 0 0 #F6F6F6;
  color            :#000000;
  font             :medium/1em monospace;
  margin           :1em 0 0 1em;
  padding          :0;
  word-wrap        :break-word;
}

#sidebar #CustomSearch1 {
  width            : 255px;
}

/* ================================================================ */
#sidebar table.gsc-search-box, #sidebar table.gsc-search-box * {
  font-family      :monospace;
  font-size        :medium;
  font-style       :normal;
  font-variant     :normal;
  font-weight      :normal;
  letter-spacing   :0;
  line-height      :1em;
  margin           :0;
  padding          :0;
  text-transform   :none;
  word-spacing     :0;
  word-wrap        :normal;
}

#sidebar table.gsc-search-box {
  border-collapse  :collapse;
  border-spacing   :0;
  border-style     :none;
  border-width     :0;
  margin-bottom    :2px;
  width            :100%;
}

#sidebar table.gsc-search-box td.gsc-input {
  background-color :#FFFFFF;
  border           :1px solid gray;
  margin           :0;
  padding          :0;
  width            :99%;
}

#sidebar input.gsc-input {
  background-color :#FFFFFF;
  border-width     :0;
  height           :1.5em;
  line-height      :1.5em;
  margin           :0;
  overflow         :hidden;
  padding          :0;
  vertical-align   :middle;
  width            :100%;
}

#sidebar table.gsc-search-box td.gsc-search-button {
  background-color :buttonface;
  border           :1px solid gray;
  margin           :0;
  padding          :0;
  vertical-align   :middle;
  width            :1%;
}

#sidebar input.gsc-search-button {
  background-color :buttonface;
  border-width     :0;
  cursor           :pointer;
  height           :1.5em;
  line-height      :1.5em;
  margin           :0;
  padding          :0;
  width            :3em;
}
/* ================================================================ */

     -->
  </style>
 </head>
 <body>
  <div id="sidebar">
   <div class="widget CustomSearch" id="CustomSearch1">
    <h2 class="title">このブログを検索</h2>
    <div class="widget-content">
     <div id="CustomSearch1_form">
      <form accept-charset="utf-8" class="gsc-search-box">
       <table cellspacing="0" cellpadding="0" class="gsc-search-box">
        <tbody>
         <tr>
          <td class="gsc-input"><input type="text" value="あいうえお" title="検索" name="search" class=" gsc-input" size="10" autocomplete="off" /></td>
          <td class="gsc-search-button"><input type="submit" title="検索" class="gsc-search-button" value="検索" /></td>
         </tr>
        </tbody>
       </table>
      </form>
     </div>
    </div>
   </div>
  </div>
 </body>
</html>

2010-05-15

formタグのmarginの単位をemにするとhtmlタグのfont-sizeを継承する例

IE6 or IE7 or IE8の互換モードで確認します。
formタグの中でmarginとfloatを同時に使う場合は、font-sizeがhtmlタグと同じ必要があるかもしれません。
例えば、formタグがfont-size:smallで、htmlタグがfont-size:mediumの場合、1emにつき3px多くmarginが発生するかもしれません。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--<?xml version="1.0" encoding="UTF-8"?>-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
 <head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <style type="text/css">
   <!--
* {
  margin: 0;
  padding: 0;
}

html {
  font-size: 100px;
}

body {
  font-size: 15px;
  padding: 1em;
}

p {
  font-size: medium;
  clear: both;
}

div, div button, form, form button {
  font-size: small;
}

div button, form button {
  border: 1px solid gray;
  float: left;
  margin-left: 1em;
  padding-left: 7em;
  width: 8em;
  height: 2em;
}

div button {
  background-color: #faa;
}

form button {
  background-color: #afa;
}
     -->
  </style>
 </head>
 <body>
  <p>div</p>
  <div>
   <button>1</button><button>2</button><button>3</button>
  </div>
  <p>form</p>
  <form>
   <button>1</button><button>2</button><button>3</button>
  </form>
 </body>
</html>