作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道如何使用另一个功能禁用一个功能。我有一个表格要求额外的类(class)作业,但如果用户没有完成任何额外的工作,则隐藏输入。我想安装一个故障保护装置,以防他们删除输入集并改变主意。
我需要帮助的是编写故障安全函数来检查:如果函数 1 发生,则禁用它。
代码笔:http://codepen.io/theodore_steiner/pen/ORzpQQ
function hideCourseWork() {
var otherEducationHistory = document.getElementById("otherEducationHistory");
otherEducationHistory.style.display = "none";
if (otherEducationHistory.style.display == "none") {
var noAdditionalCourseWork = document.getElementById("noAdditionalCourseWork");
var checkNo = document.getElementById("checkNo");
var undo = document.getElementById("undoNoAdditionalCourseWork");
noAdditionalCourseWork.style.top = "-48px";
checkNo.style.top = "-65px";
undo.style.top = "-65px";
undo.style.top = "-63px";
}
};
<div class="input-group" id="other-education">
<p class="subtitleDirection">Please list in chronological order, any additional cources beyond the degree(s) listed above, including any Ministry of Education Courses. If you have not completed any additional course work, please indicate.</p>
<div class="clearFix"></div>
<label id="otherEducation">Additional Courses*</label>
<div id="otherEducationHistory">
<input type="text" class="three-lines" name="otherUniversity_1" placeholder="Institution" onblur="this.placeholder='Institution'" onfocus="this.placeholder=''" />
<input type="text" class="three-lines" name="otherDegree_1" placeholder="Degree/Diploma" onblur="this.placeholder='Degree/Diploma'" />
<input type="date" class="three-lines" name="otherEducationYear_1" />
<input type="button" value="+" onclick=addOtherEducation() />
</div>
<!--end of otherEducationHistory div-->
<div class="clearFix"></div>
</div>
<!--end of other-education div-->
<p id="noAdditionalCourseWork">I have not completed any additional course work.</p>
<input type="radio" name="checkNo" id="checkNo" onclick="hideCourseWork()" />
<br />
<p id="undoNoAdditionalCourseWork" onclick="reAddCourseWork()">(Undo).</p>
最佳答案
您的问题不是很清楚,但也许这会有所帮助。
函数与变量有点相似。它们可以被重新分配,(例如,像一个空函数)..
function doSomething(){
alert("didSomething");
}
function disableDoSomething(){
window.doSomething = function(){};
}
如果您希望以后能够重新启用该功能,您可以这样做...
function doSomething(){
alert("didSomething");
}
var functionHolder;
function disableDoSomething(){
if(!functionHolder) functionHolder = window.doSomething;
window.doSomething = function(){};
}
function enableDoSomething(){
window.doSomething = functionHolder;
}
关于javascript - 使用另一个函数禁用一个函数 - Vanilla JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39876582/
我是一名优秀的程序员,十分优秀!