我目前有:
jQuery
$(document).ready(function () {
$('.span-fix').each(function(){ /* Do this for each extended input */
var wide = $(this).width(), /* create a variable that holds the width of the form */
label = $(this).prev('.add-on').width(); /* create another variable that holds the width of the previous label */
$(this).width( wide - label ); /* subtract the label width from the input width and apply it in px */
});
});
html
<div class="input-prepend">
<span class="add-on">Location</span>
<input name="ctl00$ContentPlaceHolder1$tbLocation" type="text" id="tbLocation" class="span12 span-fix" placeholder="Location" style="width: 97.04668304668304%; ">
</div>
显示问题的小提琴:http: //jsfiddle.net/SuguM/
但是,这会在 中应用新的宽度px
,并且我正在使用流体布局,并且需要再次将其设为百分比。
有没有办法将 apply 转换px
为 a %
?