[英]Combine Checkbox values and input values into a span text area
I have the following code: 我有以下代码:
I basically want it, where if they check a checkbox and then fill out the input on any of them, I want to update a span text with text when they hit a save button: 我基本上想要它,如果他们选中一个复选框,然后在其中任何一个上填写输入,我想在他们点击保存按钮时用文本更新跨度文本:
Example :05| 33%, :15| 33%, :60| 34%
范例
:05| 33%, :15| 33%, :60| 34%
:05| 33%, :15| 33%, :60| 34%
In the example above, the user checked the :05, :15, and :60 checkboxes and only entered those numbers. 在上面的示例中,用户选中了:05,:15和:60复选框,仅输入了这些数字。
<div class="span5 lengthcontainer">
<label class="control-label">Lengths:</label>
<div class="row day-selection">
<input name="" type="checkbox" value=":05" class="LCheckbox" id="05Checkbox" >
<label>:05 </label>
<input name="textinput" type="text" class="input-mini-length LInput" disabled>
<span>%</span>
<input name="" type="checkbox" value=":10" class="LCheckbox">
<label>:10 </label>
<input id="10Input" name="textinput" type="text" class="input-mini-length LInput" disabled>
<span>%</span>
<input name="" type="checkbox" value=":15" class="LCheckbox" >
<label>:15 </label>
<input id="textinput" name="textinput" type="text" class="input-mini-length LInput" disabled>
<span>%</span> </div>
<div class="row day-selection">
<input name="" type="checkbox" value=":30" class="LCheckbox" >
<label>:30 </label>
<input id="textinput" name="textinput" type="text" class="input-mini-length LInput" disabled>
<span>%</span>
<input name="" type="checkbox" value=":60" class="LCheckbox" >
<label>:60 </label>
<input id="textinput" name="textinput" type="text" class="input-mini-length LInput" disabled>
<span>%</span>
<input name="" type="checkbox" value=":60+" class="LCheckbox">
<label>:60+</label>
<input id="textinput" name="textinput" type="text" class="input-mini-length LInput" disabled>
<span>%</span> </div>
</div>
Sorry: Here is the jquery I used to get the checkbox values, and this works. 抱歉:这是我用来获取复选框值的jquery,它可以正常工作。 Just not sure how to include the input:text fields to it.
只是不确定如何在其中包括input:text字段。
var tempLengthValue='';
tempLengthValue=$('.lengthcontainer input:checkbox').map(function(n){
if(this.checked){
return this.value;
}
;}).get().join(' , ');
$('#Length-lbl').html(tempLengthValue);
In short: 简而言之:
//Enable the textbox
$(":checkbox").change(function() {
$(this).nextUntil(":text").prop("disabled", !this.checked);
});
$(":text").change(function() {
var radio = $(this).prevUntil(":checkbox").val();
$(this).next("span").text(radio + "| " + $(this).text());
});
(Untested) (未经测试)
Answered it, this is for anyone who needs this kind of answer: 回答了,这是给需要这种答案的任何人的:
var tempLengthValue='';
tempLengthValue=$('.lengthcontainer input:checkbox').map(function(n){
if(this.checked){
return this.value + ' @ ' + $(this).parent().children('input:text').val() + '%';
}
;}).get().join(' , ');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.