jQuery: fire click() before blur() event

Posted by & filed under JavaScript.

Solution 1

Listen to mousedown instead of click.

The mousedown and blur events occur one after another when you press the mouse button, but click only occurs when you release it.

Solution 2

You can preventDefault() in mousedown to …

固定宽度下拉列表中option内容显示不全问题解决方法

Posted by & filed under JavaScript.

不少时候在页面中为了布局的需要,下拉列表<select>的宽度需要设成比较小的值,这时如果恰巧它包含的选择项<option>的内容比较长,那么超出select宽度的部分将会被截断,如果option显示的内容又比较重要,必须完整地展现出来,或者你是个完美主义者,那这就成了一个不大不小的问题了。

在IE7+、Firefox中,由于支持了<option>的title属性,我们可以想办法给option标记设置title属性(内容可以与显示的值相同或者不同)。如果是已经做好的页面,不想再做太多改动,可以用下面的脚本,自动遍历页面上的所有<select>,给所有的option加上与text相同的title。

function SetOptionTitle()
{
    var selects = document.getElementsByTagName(“select”);
    if (selects.length > 0)
    {
        for (var i = 0; i < selects.length; i++)
        {
            var options = selects[i].options;
            if (selects[i].options.length > 0)
            {
                for (var j = 0; j < 

ラジオボタンにはlabelタグのforが便利

Posted by & filed under JavaScript.

Zopeジャンキー日記 :ラジオボタンにはlabelタグのforが便利:

はてなブックマークの「注目エントリー」で、3ユーザと5ユーザの切替ボタンが、
ラベルと連動していないことに気づいた。

HTMLソースでいうと、いま

<input value=”3″ name=”threshold” type=”radio”>
3users
<input value=”5″ name=”threshold” type=”radio”>
5users

のようになっていますが(ちょっと簡略化しています)、

<input value=”3″ name=”threshold” type=”radio” id=”button1″ />
<label for=”button1″>3users</label>
<input value=”5″ name=”threshold” type=”radio” id=”button2″ />
<label for=”button2″>5users</label>

のようにすれば、ラベル部分もクリックできるようになります。

私はこの切替ボタンをよく押すので、

Dict lookup

Posted by & filed under JavaScript.

Dict lookup:

Dict lookup

This MS IE 4+ add-on lets you easily look up words using the dict.org server. Just highlight the word, right click, and chose dict. A new window will open with the dict.org page and the …