使用另一个功能禁用功能 - Vanilla JS

时间:2016-10-05 14:22:32

标签: javascript html css

我想知道我是如何使用其他功能来禁用某个功能的。我有一个表格要求额外的课程作业,但如果用户没有完成任何额外的工作,则隐藏输入。如果他们删除了一组输入并改变了主意,我想加入一个故障保险。

我需要帮助的是编写故障保护功能,检查:如果功能1发生,请将其禁用。

CodePen:http://codepen.io/theodore_steiner/pen/ORzpQQ



Retry-After

 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";
   }

 };




2 个答案:

答案 0 :(得分:1)

你对自己的问题并不是很清楚,但也许这会有所帮助。

函数与变量是一回事。它们可以被重新分配(例如,对于空函数)..

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;
}

答案 1 :(得分:1)

{c.name: c.foreign_keys for c in table.columns if len(c.foreign_keys) > 0}

为了后人(ES5):

var foo = () => { /* foo definition */ },
    bar = foo;

/* re-assign foo to a new, empty, function implementation;
   effectively "disabling" it */
foo = () => {};

/* ... code that uses function reference foo ...*/

/* re-enable foo's original behavior by assigning bar to foo */
foo = bar;