在input标签的style属性中使用变量

时间:2009-06-26 09:10:20

标签: jquery html

我有一个包含三个值的下拉框,小,中,大。如果值很小,创建的文本应该是100px,如果是中等则200px,如果大,400px。基于此值,我可以将大小保存在变量中,并在样式属性中使用该变量吗?

例如,  我得到下拉框的值为

fieldsize=$('#fieldSize').fieldValue(); 

我可以代码,            如果(字段大小== “小”){大小= 100;} 并在style属性中使用该size变量? (style ='width:size px')

if(fieldType=="text"){
$("<input id=inputstr"+increment+" type= 'text' style= 'width:100px'></input><br><br>").appendTo("#fb_contentarea_col1down21");
}

1 个答案:

答案 0 :(得分:1)

只需执行switch语句即可检查fieldSize的值 小=“100px” medium =“200px” large =“400px”

然后在你的追加代码中写下$("<input style='width:"+fieldWidth+";' ... >")

相关问题