gpt4 book ai didi

javascript - 使用另一个函数禁用一个函数 - Vanilla JS

转载 作者:行者123 更新时间:2023-11-30 11:49:39 25 4
gpt4 key购买 nike

我想知道如何使用另一个功能禁用一个功能。我有一个表格要求额外的类(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com