2012-01-19 64 views
0

我需要創建一個函數: onMouseDown添加該類,onChange其他類和onBlur最後一個類。 「.animate」更美妙,但即使沒有,也可以。在一個函數中添加更多的CSS類

onMouseDown="this.className='styleDropDownClick'; 
onChange="this.className='styleDropDown'"; 
onBlur="this.className='styleDropDown'; 

如果anyoane可以幫助我,謝謝。

回答

0

嘗試以下功能:

function styleDropDownClick() { 

     var textForm = document.forms["textForm"]; 
     textForm.fname.setAttribute("class", "styleDropDownClick"); 
    } 
    function styleDropDown() { 
     var textForm = document.forms["textForm"]; 
     textForm.fname.setAttribute("class", "styleDropDown"); 
    } 

這適用於以下HTML:

<form id="textForm"> 
     <input type="text" class="styleDropDown" name="fname" 
      onBlur="styleDropDown()" onChange="styleDropDown()" onMouseDown="styleDropDownClick()" value="test"/> 
     <input type="text" class="styleDropDown" name="fname2" value="test2"/> 
    </form> 
+0

沒有真正的工作,看到的例子:http://jsfiddle.net/DCjYA/130/。這個選擇並沒有擴展IE8的所有數值寬度:( – mcmwhfy

+0

你的意思是它不起作用嗎?在我給出的例子中,我測試了一個有姓名(不是id)fname,並且包裝在名稱爲的表單中。實際上,我將編輯我的答案。 – wmorrison365

+0

在您的示例中,即使您沒有表單,也會逐字複製代碼所謂的textForm。另外,你選擇的類是「styleDDC」,而不是CSS中的「styleDropDownClick」。將上面的函數和HTML複製到一個文本文件中(使用和你自己的CSS等)。非常明顯,所以變化是顯而易見的(改變顏色或其他東西)。希望這有助於您! – wmorrison365

0

固定!我的問題是,select的子節點沒有用自動寬度或給定的寬度擴展。

$("select").click(function() { 
    $(this).children().addClass("cooling"); 
    }); 

這裏有一個例子,它僅適用於IE

http://jsfiddle.net/DCjYA/132/

相關問題