html+js 问卷调查页面的展示以及form提交

vine666 2021-09-02 原文


html+js 问卷调查页面的展示以及form提交


从数据库查到问题的种类,选择种类则显示该种类的子问题,多选,点击则取消选择

子问题:

当选项为可输入时,点击该选项,则出现输入框,选择其他选项时,改输入框消失

 

 

html部分:

 

 

<body >
<div data-role=”page” >
<div data-role=”header”
style=”border: 0; background: #FBCDCA; text-align: center; height: 55px;”>
<div style=”padding-top: 3px;”>
<p>
<b>调查问卷</b>
</p>
</div>

</div>
<div data-role=”main” id=”main”>
<div id=”outer”>
<form onsubmit=”return check()” action=”saveQuestionnairersponse” method=”post”  >
<div class=”type”>
<div class=”question”>
请选择你要调查的问题类型:
</div>
<div class=”answer”>
<c:forEach var=”type” items=”${typelist}” varStatus=”status”>
<input type=”radio” onclick=”showChild(this,${status.index})” />${type.qtName}<br />
</c:forEach>
</div>
</div>
<c:forEach var=”type” items=”${typelist}” varStatus=”status”>
<div id=”type${status.index}” style=”display: none;”>
<c:forEach var=”question” items=”${questionList}” varStatus=”q”>
<c:if test=”${question.qtId == type.qtId}”>
<div class=”question”>
${question.questionContent}
</div>
<div class=”answer” id=”answer${q.index}”>
<c:forEach var=”option” items=”${optionList}” varStatus=”s”>
<c:if test=”${option.tquestioninfo.questionId == question.questionId}”>
<input type=”radio” id=”op${s.index}” name=”questionnairersponse[${q.index}].tquestionoptionsinfo.optionId” value=”${option.optionId}” class=”option” onchange=”change(${q.index})”/>${option.optionContent}<br />
<div >
<c:if test=”${option.isWrite==1}” >
<div id=”table${s.index}” style=”display: none”>
<table
style=”border-bottom: 1px solid green; width: 80%”
cellpadding=”0″ cellspacing=”0″>
<tr>
<td>
<input type=”text” style=”border: 0; background: #FEFCC8; width: 100%;”
name=”questionnairersponse[${q.index}].writeContent” id=”write${s.index}”/>
</td>
</tr>
</table>
</div>
</c:if>
</div>
</c:if>
</c:forEach>
</div>
</c:if>
</c:forEach>

</div>
</c:forEach>

<div style=”margin-top: 20px;”>
<input type=”submit” value=”提交问卷” style=”background-color: #FBCDCA;border:0″ />
</div>

</form>

</div>
</div>

</div>
</body>

 

js部分:

 

<script type=”text/javascript”>
var length = “${fn:length(typelist)}”;
var questionLength = “${fn:length(questionList)}”;
var optionLength = “${fn:length(optionList)}”;
var tempradio = new Array();
function showChild(checkedRadio, index) {
for ( var i = 0; i < length; i++) {
if (index == i) {
var subQuestion = “type” + i;
if (tempradio[i] == checkedRadio) {
checkedRadio.checked = false;
document.getElementById(subQuestion).style.display = “none”;
tempradio[i] = null;

} else {
document.getElementById(subQuestion).style.display = “block”;
tempradio[i] = checkedRadio;
}
}
}
}

function change(answerId) {
var questionId = “answer” + answerId;
var v = document.getElementById(questionId).getElementsByTagName(“input”);
for ( var i = 0; i < v.length; i++) {
if (v.item(i).checked) {
var inputID = v.item(i).id;
var tableId = “table” + inputID.substring(2, 3);
var writeTable = document.getElementById(tableId);
if (writeTable != null) {
writeTable.style.display = “block”;

}
for ( var j = 0; j < v.length; j++) {
if (i != j) {
var inputID = v.item(j).id;
var writeId = “write” + inputID.substring(2, 3);
var writeText = document.getElementById(writeId);
if (writeText != null) {
writeText.value = “”;
}
}
}
} else {
var inputID = v.item(i).id;
var tableId = “table” + inputID.substring(2, 3);

var writeTable = document.getElementById(tableId);

if (writeTable != null) {
writeTable.style.display = “none”;
}
}
}

}
function check() {
var sum = 0;
for (var i = 0; i < optionLength; i++) {
var questionId = “op” + i;
var v = document.getElementById(questionId);
if(v.checked) {
sum+=1;
}

}
if (sum > 0) {
return true;
} else {
return false;
}

}

发表于
2016-05-23 19:42 
吃完草莓吃芒果 
阅读(9005
评论(0
编辑 
收藏 
举报

 

版权声明:本文为vine666原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/vine666/p/5521198.html

html+js 问卷调查页面的展示以及form提交的更多相关文章

随机推荐

  1. 初识Python

    目录 列表和元组 字典 副本问题 可变参数 参数列表解析 @(目录) 列表和元组     列表就是所谓的数组, […]...

  2. 7.逻辑回归实践

    7.逻辑回归实践 1.逻辑回归是怎么防止过拟合的?为什么正则化可以防止过拟合?(大家用自己的话介绍下) 答:防 […]...

  3. [luogu1265]公路修建

    传送门 你会发现第二条规则不存在,因为在形成环之前,这几个城市就已经连通了。所以直接求最小生成树即可。 然后你 […]...

  4. 《机器学习技法》—核型SVM

    (本文内容和图片来自林轩田老师《机器学习技法》) 1. 核技巧引入   如果要用SVM来做非线性的分类,我们采 […]...

  5. linux每日命令(35):grep命令

    Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来。gr […]...

  6. Web离线应用解决方案——ServiceWorker

    什么是ServiceWorker   在介绍ServiceWorker之前,我们先来谈谈PWA。PWA (Pr […]...

  7. css加载会造成阻塞吗

    本文由云+社区发表 作者:嘿嘿嘿 可能大家都知道,js执行会阻塞DOM树的解析和渲染,那么css加载会阻塞DO […]...

  8. 跟我学算法-图像识别之图像分类(下)(GoogleNet网络, ResNet残差网络, ResNext网络, CNN设计准则)

    1.GoogleNet 网络:              Inception V1 – Incep […]...

展开目录

目录导航