【问题标题】:using a variable in the input tag's style attribute在输入标签的样式属性中使用变量
【发布时间】:2009-06-26 09:10:20
【问题描述】:

我有一个下拉框,包含三个值,小、中和大。如果值小,创建的文本应该是 100 像素,如果是中则 200 像素,如果大,则创建 400 像素。我可以根据这个值将大小保存在变量中,并在样式属性中使用该变量吗?

例如, 我将下拉框的值设为

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

我可以编码吗, if(fieldsize=="small"){size=100;} 并在样式属性中使用该大小变量? (style= 'width:size px')

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

【问题讨论】:

    标签: jquery html


    【解决方案1】:

    只需做一个 switch 语句来检查 fieldSize 的值 小 = "100px" 中 =“200 像素” 大 = "400px"

    然后在你的附加代码中写$("&lt;input style='width:"+fieldWidth+";' ... &gt;")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-08
      • 2018-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-01
      • 1970-01-01
      • 2013-10-21
      相关资源
      最近更新 更多