我进行了一项调查,要求参加者填写所有字段,但是不知何故,我在输出文件中的“ title2”和“ dept2”列中有空白条目。我相信,如果他们在空格中没有提供答案,它将显示为“ {}”。但是这些条目完全是空白的,我无法理解。我想知道是否有任何普遍的错误会引起这个问题。整个代码在下面提供。谢谢。
<p> </p>
<link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" integrity="sha384- IS73LIqjtYesmURkDE9MXKbXqYA8rvKEp/ghicjem7Vc3mGRdQRptJSz60tvrB6+" rel="stylesheet" />
<meta content="width=device-width,initial-scale=1" name="viewport" />
<p> </p>
<section class="container" id="TranscriptionFromAnImage"><!-- Instructions -- >
<div class="row">
<div class="col-xs-12 col-md-12">
<div class="panel panel-primary"><a class="panel-heading"><strong>Table transcription instructions</strong> </a>
<p> </p>
<p><span style="font-family:arial,helvetica,sans-serif;">F</span><span style="font-family: arial, helvetica, sans-serif;">or each job (up to two) that this person has had since he/she received his/her </span><span style="font- family: arial, helvetica, sans-serif;">Ph.D.</span><span style="font-family: arial, helvetica, sans-serif;">, please copy and paste the related sections from this CV whenever possible:</span></p>
<ol style="font-size: 14px;">
<li>
<p><span style="font-family:arial,helvetica,sans-serif;">The institution for which he/she has worked</span></p>
</li>
<li>
<p><span style="font-family:arial,helvetica,sans-serif;">His/her department in the institution</span></p>
</li>
<li>
<p><span style="font-family:arial,helvetica,sans-serif;">The title of his/her job</span></p>
</li>
<li>
<p><span style="font-family:arial,helvetica,sans-serif;">Start year</span> </p>
</li>
<li>
<p><span style="font-family:arial,helvetica,sans-serif;">The year in which he/she left the job </span></p>
</li>
</ol>
<p>When some of this information is not present in the C.V. leave the related sections blank..</p>
<p>// AND if "Other" is an option, select "Other" and type "NA" in the blank space provided. If "Other" is not an option, only type "NA" in the blank space provided. <span style="font-family: arial, helvetica, sans-serif;">If the person has had only one job since getting his/her Ph.D., follow this procedure for the questions related to the second job. //</span></p>
<p>As a rule of thumb, if the start year of a job is specified but the end year is not, select "Ongoing" for the end year.</p>
<p>Please check the two links below as a reference.</p>
<div align="left"><font color="red">Link to the first example:<a href="https://image.ibb.co/fU2VxT/example_for_mturk.png">link</a></font></div>
<div align="left"><font color="red">Link to the second example: <a href="https://image.ibb.co/cVJg2T/example_mturk_with_department.png">link</a></font></div>
<div align="left"> </div>
</div>
</div>
</div>
<iframe height="1000" src="${pdf_url}" width="700"></iframe>
<div class="col-xs-12 col-sm-4 fields">
<div class="form-group"> </div>
<div class="form-group"><strong><font color="red">Questions related to the FIRST job after receiving Ph.D.</font></strong></div>
<div class="form-group"><label for="TranscriptionTexts">1. Copy and paste the name of the institution for which this person worked for</label><textarea class="form-control" cols="250" id="1st_inst" name="1st_inst" required="" rows="1"></textarea></div>
<p> </p>
<div class="form-group"><label for="TranscriptionTexts">2. Select the option "Economics department" if his/her job is at an economics department. Otherwise, select "Other" and copy and paste his department or division in the institution</label></div>
<div class="radio-inline"><label><input autocomplete="off" id="option1" name="dept1" required="" type="radio" value="econdept" /> Economics department</label></div>
<div class="radio"><label><input autocomplete="off" id="option2" name="dept1" required="" type="radio" value="other" />Other</label><textarea class="form-control" cols="250" id="1st_dept_other" name="1st_dept_other" rows="1"> </textarea></div>
<div class="form-group"> </div>
<div class="form-group"><label for="TranscriptionTexts">3. Select the title of this person's first job. If the title is neither "Assistant Professor" nor "Post-doc", select "Other" and copy and paste the title from the CV</label></div>
<div class="radio-inline"><label><input autocomplete="off" id="option1" name="title1" required="" type="radio" value="ap" /> Assistant professor </label> </div>
<div class="radio-inline"><label><input autocomplete="off" id="option2" name="title1" required="" type="radio" value="postdoc" />Post-doc</label></div>
<div class="radio"><label><input autocomplete="off" id="option3" name="title1" required="" type="radio" value="other" />Other</label><textarea class="form-control" cols="250" id="1st_title_other" name="1st_title_other" rows="1"></textarea></div>
<div class="form-group">
<p> </p>
<p><label class="group-label">4. Select the start year of this job from the drop-down menu below</label></p>
<input list="startyr1" name="startyr1" placeholder="Choose start year" /> <datalist id="startyr1"><option value="2017"></option><option value="2018"> </option><option value="NA"></option></datalist></div>
<div class="form-group">
<p> </p>
<p><label class="group-label">5. Select the end year of this job from the drop-down menu below. If still holding the position, select "Ongoing" from the menu.</label></p>
<input list="endyr1" name="endyr1" placeholder="Choose end year" /> <datalist id="endyr1"><option value="2017"></option><option value="2018"></option><option value="Ongoing"></option><option value="NA"></option></datalist></div>
<div class="form-group"> </div>
<div class="form-group"><strong><font color="red">Questions related to the SECOND job after receiving Ph.D.</font></strong></div>
<div class="form-group"><label for="TranscriptionTexts">6. </label><span style="font-weight: 700;">Copy and paste the name of the institution for which this person worked for</span><textarea class="form-control" cols="250" id="2nd_inst" name="2nd_inst" required="" rows="1"></textarea></div>
<div class="form-group"><label for="TranscriptionTexts">7. </label><span style="font-weight: 700;">Select the option "Economics department" if his/her job is at an economics department. Otherwise, select "Other" and copy and paste his department or division in the institution</span> </div>
**<div class="radio-inline"><label><input autocomplete="off" id="option1" name="dept2" required="" type="radio" value="econdept" /> Economics department </label></div>
<div class="radio"><label><input autocomplete="off" id="option2" name="dept2" required="" type="radio" value="other" />Other</label><textarea class="form- control" cols="250" id="2nd_dept_other" name="2nd_dept_other" rows="1"> </textarea></div>
<div class="form-group"> </div>
<div class="form-group"><label for="TranscriptionTexts">8. </label><span style="font-weight: 700;">Select the title of this person's first job. If the title is neither "Assistant Professor" nor "Post-doc", select "Other" and copy and paste the title from the CV</span></div>
<div class="radio-inline"><label><input autocomplete="off" id="option1" name="title2" required="" type="radio" value="ap" /> Assistant professor </label></div>
<div class="radio-inline"><label><input autocomplete="off" id="option2" name="title2" required="" type="radio" value="postdoc" />Post-doc</label></div>
<div class="radio"><label><input autocomplete="off" id="option3" name="title2" required="" type="radio" value="other" />Other</label><textarea class="form-control" cols="250" id="2nd_title_other" name="2nd_title_other" rows="1"></textarea></div>**
<div class="form-group">
<p> </p>
<p><label class="group-label">9. Choose the start year from the drop-down menu below</label></p>
<input list="startyr2" name="startyr2" placeholder="Choose start year" /> <datalist id="startyr2"><option value="2017"></option><option value="2018"></option><option value="NA"></option></datalist></div>
<div class="form-group">
<p><label class="group-label">10. Select the end year of this job from the drop-down menu below. If still holding the position, select "Ongoing" from the drop-down menu.</label></p>
<input list="endyr2" name="endyr2" placeholder="Choose end year" /> <datalist id="endyr2"><option value="2017"></option><option value="2018"></option><option value="NA"></option><option value="Ongoing"></option></datalist></div>
<!-- End Image Transcription Layout --><!-- Open internal style sheet -->
<style type="text/css">#collapseTrigger{ color:#fff; display: block; text-decoration: none; } #submitButton{ white-space: normal; } .image{ margin-bottom: 15px; } .group-label{ display: block; } .radio-inline>label{ font-weight: normal; }
</style>
<!-- Close internal style sheet --><!-- Please note that Bootstrap CSS/JS and JQuery are 3rd party libraries that may update their url/code at any time. Amazon Mechanical Turk (MTurk) is including these libraries as a default option for you, but is not responsible for any changes to the external libraries --><script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js" integrity="sha384-s1ITto93iSMDxlp/79qhWHi+LsIi9Gx6yL+cOKDuymvihkfol83TYbLbOw+W/wv4" crossorigin="anonymous"></script><script>
$(document).ready(function() {
// Instructions expand/collapse
var content = $('#instructionBody');
var trigger = $('#collapseTrigger');
content.hide();
$('.collapse-text').text('(Click to expand)');
trigger.click(function(){
content.toggle();
var isVisible = content.is(':visible');
if(isVisible){
$('.collapse-text').text('(Click to collapse)');
}else{
$('.collapse-text').text('(Click to expand)');
}
});
// end expand/collapse
});
</script></div>
</section>
<p> </p>
答案 0 :(得分:1)
条目可能不止一个空格,而不能为空String
。
您可以使用以下函数来检查String
是否为空,为空或仅包含空格:
function isNullOrEmpty(str){
return !str.trim().length;
}
<input id="testinput" type="text" onkeyup="checkEmpty()"/>
<br/>
<span id="result"></span>
<script>
var result = document.getElementById("result");
function isNullOrEmpty(str){
return !str.trim().length;
}
function checkEmpty(){
var input = document.getElementById("testinput").value;
if(isNullOrEmpty(input)){
result.innerHTML = "Empty string";
} else {
result.innerHTML = "Non-empty string";
}
}
</script>
具有检查是否填写了所有字段的表格:
<form id="thisForm">
<label for="username"><b>Username:</b></label><br/>
<input type="text" id="username">
<br/>
<label for="password"><b>Password:</b></label><br/>
<input type="password" id="password">
<br/>
<input type="button" value="Submit" onClick="validateForm()">
</form>
<span id="result"></span>
<script>
var result = document.getElementById("result");
function isNullOrEmpty(str){
return !str.trim().length;
}
function validateForm(){
result.innerHTML = "";
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var passed = true;
if(isNullOrEmpty(username)){
result.innerHTML += "<p/><b style='color: red;'>Username can not be empty!</b>";
passed = false;
}
if(isNullOrEmpty(password)){
result.innerHTML += "<p/><b style='color: red;'>Password can not be empty!</b>";
passed = false;
}
if(passed){
document.getElementById("thisForm").style.display = "none";
result.innerHTML = "<h1>Form submitted successfully!</h1>";
}
}
</script>