2012-10-11 37 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