<div class="icheck-row input-group-others">
<input class="cs" id="LE_PREPARE_CODES_closewindow" name="LE_PREPARE_CODES" type="checkbox" value="關閉門窗" data-value_closewindow="2" />
<label for="LE_PREPARE_CODES_關閉門窗">關閉門窗</label>
<input class="cs" id="LE_PREPARE_CODES_closefan" name="LE_PREPARE_CODES" type="checkbox" value="關閉冷氣/電風扇" data-value_closefan="2" />
<label for="LE_PREPARE_CODES_關閉冷氣/電風扇">關閉冷氣/電風扇</label>
<input class="cs" id="LE_PREPARE_CODES_prepare" name="LE_PREPARE_CODES" type="checkbox" value="用物準備齊全" data-value_prepare="2" />
<label for="LE_PREPARE_CODES_用物準備齊全">用物準備齊全</label>
</div>
jquery
$(function () {
$('.cs').on('change', function () {
calculateScore();
});
calculateScore();
})
function getValue(str) {
if (isNaN(str)) return 0;
else return parseInt(str, 10);
}
function calculateScore() {
var closewindow = getValue($('input[id="LE_PREPARE_CODES_closewindow"]:checked').attr('data-value_closewindow'));
var closefan = getValue($('input[id="LE_PREPARE_CODES_closefan"]:checked').attr('data-value_closefan'));
var prepare = getValue($('input[id="LE_PREPARE_CODES_prepare"]:checked').attr('data-value_prepare'));
var s1 = 6;
var score1 = s1 - closewindow - closefan - prepare;
$('#LE_PREPARE_SCORE').val(score1);
}
屬性
public List<string> LE_PREPARE_CODES { get; set; }
public string LE_PREPARE_CODE { get; set; }
畫面
資料庫的值
我傳入資料庫的是LE_PREPARE_CODE這個屬性,為了傳入一個以上的選項
另外新增了LIST屬性
RAZOR語法:
<div class="icheck-row input-group-others">
<div class="form-check">
<input asp-for="LE_PREPARE_CODE" class="form-check-input cs" id="LE_PREPARE_CODES_closewindow" value="關閉門窗" data-value_closewindow="2" />
<label class="form-check-label" for="LE_PREPARE_CODES_關閉門窗">關閉門窗</label>
</div>
<div class="form-check">
<input asp-for="LE_PREPARE_CODE" class="form-check-input cs" id="LE_PREPARE_CODES_closefan" value="關閉冷氣/電風扇" data-value_closefan="2" />
<label class="form-check-label" for="LE_PREPARE_CODES_關閉冷氣/電風扇">關閉冷氣/電風扇</label>
</div>
<div class="form-check">
<input asp-for="LE_PREPARE_CODE" class="form-check-input cs" id="LE_PREPARE_CODES_prepare" value="用物準備齊全" data-value_prepare="2" />
<label class="form-check-label" for="LE_PREPARE_CODES_用物準備齊全">用物準備齊全</label>
</div>
</div>
<script>
$(function () {
$('.cs').on('change', function () {
calculateScore();
});
calculateScore();
});
function getValue(str) {
if (isNaN(str)) return 0;
else return parseInt(str, 10);
}
function calculateScore() {
var closewindow = getValue($('input[id="LE_PREPARE_CODES_closewindow"]:checked').attr('data-value_closewindow'));
var closefan = getValue($('input[id="LE_PREPARE_CODES_closefan"]:checked').attr('data-value_closefan'));
var prepare = getValue($('input[id="LE_PREPARE_CODES_prepare"]:checked').attr('data-value_prepare'));
var s1 = 6;
var score1 = s1 - closewindow - closefan - prepare;
$('#LE_PREPARE_SCORE').val(score1);
}
</script>
記得在C#屬性上面加上[FromForm]屬性
[FromForm]
public string LE_PREPARE_CODE { get; set; }