2012-10-11 44 views
0

設置樣式寬/高我有這樣的身體:使用功能HTML

<div id="map"style="width: 400; height: 400" ></div> 

我試圖創建一個變量,並更新它是這樣的:

<div id="map"style="width: map_size; height: map_size" ></div> 

我也嘗試創建一個功能以及設置另一種方式:

function getComboA(sel) { 
    map_size = sel.options[sel.selectedIndex].value; 
    $("#map").css("width", map_size); 
    $("#map").css("height",map_size); 

試圖到從下拉菜單中獲取map_size的值,我不確定如何測試它是否正常工作,但地圖沒有顯示。

我是新來的,所以我可能誤解了一些基本的東西,任何幫助表示讚賞。

回答

1

我在這裏創造一個演示..

http://jsfiddle.net/kN7UQ/2/

這有幫助嗎?

UPDATE

$(function(){ //document ready... be sure to start your code after the document is ready 

    $('select').bind('change', function(){ //this is binds to the 'change' event of the select box 
     var dimension = $('select').val(); //here we are taking the selected value from the select box 
     $('#map').css({ width: dimension +'px', height: dimension +'px' }); // this is where we are setting the dimension for the '#map' element, be sure to add 'px' to the dimension as i saw you didn't in your question 
    }); 

});​ 
+0

,當我在我的代碼試了一下它不工作,你能解釋一下你貼的功能?它在哪一點引用從中選擇了該值的菜單? – Mike

+0

查看上面的更新... – udidu

+0

謝謝,我仍然不清楚。在任何意義的菜單中,是不是'id'的值或函數集被調用'onchange'? 「改變」事件到底是什麼?我有幾個下拉菜單框,函數如何知道要處理哪個輸入? – Mike