207 lines
9.0 KiB
HTML
207 lines
9.0 KiB
HTML
<!DOCTYPE HTML>
|
|
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
|
|
<meta charset="utf-8">
|
|
<head th:include="include :: header"></head>
|
|
<body class="white-bg">
|
|
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
|
|
<form class="form-horizontal m" id="form-examQuestion-add">
|
|
<div class="form-group">
|
|
<input type="hidden" id="id" name="id" th:value="${examQuestion.id}">
|
|
<input type="hidden" id="categoryId" name="categoryId" th:value="${examQuestion.categoryId}">
|
|
<input type="hidden" id="type" name="type" th:value="${examQuestion.type}">
|
|
<input type="hidden" id="answer" name="questionAnswer" th:value="${examQuestion.answer}">
|
|
<input type="hidden" id="item" name="item" th:value="${examQuestionItem}">
|
|
<label class="col-sm-3 control-label">问题标题:</label>
|
|
<div class="col-sm-8">
|
|
<input id="title" name="title" class="form-control" type="text" th:value="${examQuestion.title}">
|
|
</div>
|
|
</div>
|
|
<!--<div class="form-group">-->
|
|
<!--<label class="col-sm-3 control-label">问题答案:</label>-->
|
|
<!--<div class="col-sm-8">-->
|
|
<!--<input id="answer" name="answer" class="form-control" type="text">-->
|
|
<!--</div>-->
|
|
<!--</div>-->
|
|
|
|
<div class="form-group" >
|
|
<label class="col-sm-3 control-label">问题选项:</label>
|
|
<div class="col-sm-1" style="padding-right: 0px;">
|
|
<input class="form-control" name="answer" value="A" type="radio" style="margin: 0 0 0;">
|
|
</div>
|
|
<div class="col-sm-1" style="padding-right: 0px;padding-left: 0px">
|
|
<input style="padding: 6px 10px;text-align: center" id="number1" name="number" class="form-control" type="text" value="A" readonly>
|
|
</div>
|
|
<div class="col-sm-6" style="padding-left: 0px">
|
|
<input id="content1" name="content" class="form-control" type="text">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group" >
|
|
<label class="col-sm-3 control-label"></label>
|
|
<div class="col-sm-1" style="padding-right: 0px;">
|
|
<input class="form-control" name="answer" value="B" type="radio" style="margin: 0 0 0;">
|
|
</div>
|
|
<div class="col-sm-1" style="padding-right: 0px;padding-left: 0px">
|
|
<input style="padding: 6px 10px;text-align: center" id="number2" name="number" class="form-control" type="text" value="B" readonly>
|
|
</div>
|
|
<div class="col-sm-6" style="padding-left: 0px">
|
|
<input id="content2" name="content" class="form-control" type="text">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group" id="addOption">
|
|
<label class="col-sm-4 control-label"></label>
|
|
<div class="col-sm-7" style="padding-left: 0px">
|
|
<a style="text-align: center;color: #999;border: 1px #ccc dashed;display:block;height: 34px
|
|
;line-height: 34px" href="javascript:addOption();">添加选项</a>
|
|
</div>
|
|
</div>
|
|
<!--</div>-->
|
|
|
|
<!--<div class="form-group">-->
|
|
<!--<label class="col-sm-3 control-label">标签:</label>-->
|
|
<!--<div class="col-sm-8">-->
|
|
<!--<input id="label" name="label" class="form-control" type="text">-->
|
|
<!--</div>-->
|
|
<!--</div>-->
|
|
|
|
<div class="form-group">
|
|
<label class="col-sm-3 control-label">备注信息:</label>
|
|
<div class="col-sm-8">
|
|
<input id="remarks" name="remarks" class="form-control" type="text" th:value="${examQuestion.remarks}">
|
|
</div>
|
|
</div>
|
|
|
|
</form>
|
|
</div>
|
|
<div th:include="include::footer"></div>
|
|
<script type="text/javascript">
|
|
$(function () {
|
|
|
|
|
|
if ($.validator) {
|
|
$.validator.prototype.elements = function () {
|
|
var validator = this,
|
|
rulesCache = {};
|
|
return $([]).add(this.currentForm.elements)
|
|
.filter(":input")
|
|
.not(":submit, :reset, :image, [disabled]")
|
|
.not(this.settings.ignore)
|
|
.filter(function () {
|
|
var elementIdentification = this.id || this.name;
|
|
!elementIdentification && validator.settings.debug && window.console && console.error("%o has no id nor name assigned", this);
|
|
if (elementIdentification in rulesCache || !validator.objectLength($(this).rules()))
|
|
return false;
|
|
rulesCache[elementIdentification] = true;
|
|
return true;
|
|
});
|
|
};
|
|
|
|
}
|
|
|
|
var questionItem = $("#item").val();
|
|
var questionAnswer = $("#answer").val();
|
|
questionItem =$.parseJSON(questionItem)
|
|
|
|
for(var i in questionItem){
|
|
var number = questionItem[i].number;
|
|
if(number == "A"){
|
|
$("#content1").val(questionItem[i].content);
|
|
continue;
|
|
}
|
|
if(number == "B"){
|
|
$("#content2").val(questionItem[i].content);
|
|
continue;
|
|
}
|
|
$("#addOption").before(' <div class="form-group update1" id="div'+item[index]+'"> <label class="col-sm-3 control-label"></label><div class="col-sm-1" style="padding-right: 0px;"> <input class="form-control update4" name="answer" value="'+item[index]+'" type="radio" style="margin: 0 0 0;">' +
|
|
'</div><div class="col-sm-1" style="padding-right: 0px;padding-left: 0px"> ' +
|
|
'<input style="padding: 6px 10px;text-align: center" id="number'+item[index]+'" name="number" class="form-control update2" type="text" value="'+item[index]+'" readonly> ' +
|
|
'</div> <div class="col-sm-6" style="padding-left: 0px"> <input name="content" id = "con'+item[index]+'" class="form-control" type="text" value="'+questionItem[i].content+'"> </div> <div class="col-sm-1"> <a class="update3" style="text-align: center;color: #999;border: 1px #ccc dashed;display:block;height: 34px;line-height: 34px" href="javascript:deleteOption(\''+item[index++]+'\');">X</a> </div></div>')
|
|
}
|
|
|
|
var radios = document.getElementsByName("answer");
|
|
|
|
for ( var i = 0; i < radios.length; i++) {
|
|
|
|
if (radios[i].value==questionAnswer) {
|
|
radios[i].checked=true
|
|
}
|
|
}
|
|
|
|
|
|
});
|
|
|
|
var item = ["C","D","E","F","G","H","I","G","K","L","M","N"];
|
|
var index = 0;
|
|
var prefix = ctx + "exam/examQuestion"
|
|
|
|
$("#form-examQuestion-add").validate({
|
|
rules:{
|
|
title:{
|
|
required:true,
|
|
},
|
|
content:{
|
|
required:true,
|
|
},
|
|
|
|
}
|
|
});
|
|
|
|
function submitHandler() {
|
|
debugger
|
|
if (!$.validate.form()) {
|
|
return
|
|
}
|
|
|
|
var radios = document.getElementsByName("answer");
|
|
var i = 0
|
|
for ( ; i < radios.length; i++) {
|
|
|
|
if (radios[i].checked == true) {
|
|
break;
|
|
}
|
|
}
|
|
if(i==radios.length){
|
|
$.modal.alertError("请至少选择一个答案");
|
|
return;
|
|
}
|
|
|
|
$.operate.save(prefix + "/update", $('#form-examQuestion-add').serialize());
|
|
}
|
|
|
|
|
|
|
|
function addOption(){
|
|
$("#addOption").before(' <div class="form-group update1" id="div'+item[index]+'"> <label class="col-sm-3 control-label"></label><div class="col-sm-1" style="padding-right: 0px;"> <input class="form-control update4" name="answer" value="'+item[index]+'" type="radio" style="margin: 0 0 0;">' +
|
|
'</div><div class="col-sm-1" style="padding-right: 0px;padding-left: 0px"> ' +
|
|
'<input style="padding: 6px 10px;text-align: center" id="number'+item[index]+'" name="number" class="form-control update2" type="text" value="'+item[index]+'" readonly> ' +
|
|
'</div> <div class="col-sm-6" style="padding-left: 0px"> <input name="content" id = "con'+item[index]+'" class="form-control" type="text"> </div> <div class="col-sm-1"> <a class="update3" style="text-align: center;color: #999;border: 1px #ccc dashed;display:block;height: 34px;line-height: 34px" href="javascript:deleteOption(\''+item[index++]+'\');">X</a> </div></div>')
|
|
}
|
|
|
|
function deleteOption(id){
|
|
debugger
|
|
$("#div"+id).remove();
|
|
index--;
|
|
var index1 = 0;
|
|
var index2 = 0;
|
|
var index3 = 0;
|
|
var index4 = 0
|
|
$(".update1").each(function(){
|
|
$(this).attr("id","div"+item[index1++])
|
|
})
|
|
$(".update2").each(function(){
|
|
$(this).attr("value",item[index2++])
|
|
})
|
|
$(".update3").each(function(){
|
|
$(this).attr("href",'javascript:deleteOption(\''+item[index3++]+'\');');
|
|
})
|
|
$(".update4").each(function(){
|
|
$(this).attr("value",'javascript:deleteOption(\''+item[index4++]+'\');');
|
|
})
|
|
|
|
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|