2011-07-01 29 views
1

我有下拉框,其ID名稱爲選項,ID名稱爲「清潔香港」和我的複選框的名字是「CHK」如何用JAvascript隱藏我的組合框?

,我的劇本是這個樣子,我把腳本的onclick但它不能正常工作;我檢查我的腳本正在加載;我不明白爲什麼它不起作用?你能幫我嗎?

function checkAll() 
{ 
    //do some stuff you need here 

document.getElementById('option').style="none"; 
} 

<input type=\"checkbox\" name=\"Chk\" value=\"Chk\" onclick=\"checkAll()\"> 
+0

您的目標是檢查所有複選框元素或隱藏ID ='選項'的元素? – heximal

回答

2

您需要使用display屬性:

document.getElementById('option').style.display = "none"; 

這應該工作,如果你已經指定你的元素id="option"


如果要選中該複選框(如函數顧名思義),則需要使用checked屬性代替:

document.getElementById('option').checked = true; 
+0

謝謝你的工作... – bluedoor

+0

歡迎:) – Sarfraz

+1

@LAmureTJ如果這個答案解決了你的問題,考慮[接受](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-答案)工作。 – phihag

0

你可以輕鬆地用jQuery來做到這一點。

//綁定事件複選框點擊

$(input[name=chk]).bind("click", function(e){ 
    //select all checkboxes based on any criteria, here on base of class 
    $('.chkz').attr("checked", "checked"); 
    $("#option").css("display", "none"); 
}); 

沒有必要把的onclick = 「checkall()」 這一點。 跳它有幫助,

相關問題