여기에 또 다른 도움이 필요합니다. "텍스트 상자"필드에 더하거나 뺄 수 있지만 "레이블"또는 "텍스트"필드에는 없습니다. 체크 박스의 텍스트베이스 값을 변경하고 싶습니다. 아래에 내 코드가 있습니다.
<div style="margin-bottom:10px;">
<label>CPV (RM)<strong style="margin-left:100px; color:red;" id="CPV">0.05</strong></label>
<label>CPC (RM)<strong style="margin-left:100px; color:red;" id="CPC">0.55</strong></label>
<input type="text" name="CPV"/>
</div>
<div style="margin-bottom:10px;">
<label style="float:left;">Ad Targeting</label>
<div id="ad-target-button" style="margin-left:85px;" onclick="toggle()">
<input type="checkbox" checked="checked" value="On" name="adtarget" id="adtarget_check">
</div>
</div>
<div class="row-fluid">
<label style="float:left; margin-top:5px;">Target Gender</label>
<div style="display:block;">
<label class="checkbox inline">
<input type="checkbox" value="male" id="gender_male" name="gender[]" class="gender" onclick='add(922.63, this);'/>Male
</label>
<label class="checkbox inline"><input type="checkbox" value="female" id="gender_female" name="gender[]" class="gender" onclick='add(400.3, this);/>Female
</label>
</div>
</div>
계산할 자바 스크립트 함수는 다음과 같습니다.
function correctNumber(number) {
return (parseFloat(number.toPrecision(12)));
}
function add(total, this_chk_bx) {
var CPV = (page3.CPV.value * 1);
var total = total * 1;
if (this_chk_bx.checked == true) {
//add if its checked
page3.CPV.value = correctNumber(CPV + total);
$('#CPV').text(val) = correctNumber(CPV + total);
} else {
//subtract if its unchecked
page3.CPV.value = correctNumber(CPV - total);
$('#CPV').text(val) = correctNumber(CPV - total);
}
}
이 JSFIDDLE에서 코드를 얻었습니다 : http://jsfiddle.net/kHxmG/5/ 하지만 텍스트 상자에 값을 표시하고 싶지 않습니다. 나는 그것을 <label>
.
귀하의 ID #CPV는 라벨이 아닙니다. strong-Tag에는 .text () 메소드가 없으므로 이와 같은 텍스트를 추가 할 수 없습니다.
다음과 같이 레이블의 텍스트를 변경할 수 있습니다.
document.getElementById('myLabel').innerHTML = sum;
작업 바이올린 : http://jsfiddle.net/kHxmG/19/
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다