Javascript 将复选框标签设置为右侧或固定位置
这是标准复选框的代码:Javascript 将复选框标签设置为右侧或固定位置,javascript,jquery,html,jquery-mobile,Javascript,Jquery,Html,Jquery Mobile,这是标准复选框的代码: <fieldset data-role="controlgroup"> <legend>Agree to the terms:</legend> <input type="checkbox" name="checkbox-1" id="checkbox-1" class="custom" /> <label for="checkbox-1">I agree</
<fieldset data-role="controlgroup">
<legend>Agree to the terms:</legend>
<input type="checkbox" name="checkbox-1" id="checkbox-1" class="custom" />
<label for="checkbox-1">I agree</label>
</fieldset>
同意以下条款:
我同意
如何将复选框的标签(文本)设置为右侧或固定的“px”位置
类似于使用jquery的align right
或right:50px
$(function(){
$('label[for="checkbox-1"]').css({right: 50});
});
或
$('label[for="checkbox-1"]').css({'margin-left': 50});
只需在所需标签中添加样式即可
<label for="checkbox-1" style="float:right">I agree</label>
我同意
为标签添加类名
或ID,如下所示:
<label for="checkbox-1" class="chkbox">I agree</label>
您可以为标签指定填充、边框或任何您喜欢的样式
演示:固定输入字段的宽度,标记并浮动它们 例如:
input {
width: 200px;
float:left;
}
label {
width:300px;
float:left;
}
然后清除浮动。如果html文件中有此控件
<label for="2">Laparoscopic surgery</label>
<input type="checkbox" name="question" value="14" class="clickable" id="2" />
将复选框向右浮动,将标签向左浮动,并将标签位置设置为绝对
<input type="checkbox" name="question" value="14" class="clickable" id="2"
style="float: left;"/>
<label for="2" style="float: right; position: absolute;">Laparoscopic
surgery</label>
腹腔镜
外科手术
如果您只是将标签文本放在框的右侧,而没有标签,则单击时不会选中复选框。它是否应该已经在右侧->??Sry我应该说我使用jquery mobile,复选框如下所示:。你是对的文本总是在复选框的右边,但我的意思是在“按钮”的右边
.clickable{
float: left;
}
<input type="checkbox" name="question" value="14" class="clickable" id="2"
style="float: left;"/>
<label for="2" style="float: right; position: absolute;">Laparoscopic
surgery</label>