我附上了一个显示代码的片段。我正在尝试在同一 HTML 页面上的两个不同选项卡上添加两个 Math Capture。
因此,在“新闻”选项卡上,捕获工作正常,但在“联系方式”选项卡上,数学问题不会只显示一个空白框。
但是联系人选项卡中的提交按钮在新闻选项卡中有效,但它使用新闻选项卡中的数学问题是错误的。
我不确定如何让它在两个页面上都起作用?
希望你能帮忙??
谢谢
蒂姆
function openPage(pageName, elmnt, color) {
// Hide all elements with class="tabcontent" by default */
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
// Remove the background color of all tablinks/buttons
tablinks = document.getElementsByClassName("tablink");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].style.backgroundColor = "";
}
// Show the specific tab content
document.getElementById(pageName).style.display = "block";
// Add the specific color to the button used to open the tab content
elmnt.style.backgroundColor = color;
}
// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
var total;
function getRandom(){return Math.ceil(Math.random()* 20);}
function createSum(){
var randomNum1 = getRandom(),
randomNum2 = getRandom();
total =randomNum1 + randomNum2;
$( "#question" ).text( randomNum1 + " + " + randomNum2 + "=" );
$("#ans").val('');
checkInput();
}
function checkInput(){
var input = $("#ans").val(),
slideSpeed = 200,
hasInput = !!input,
valid = hasInput && input == total;
$('#message').toggle(!hasInput);
$('button[type=submit]').prop('disabled', !valid);
$('#success').toggle(valid);
$('#fail').toggle(hasInput && !valid);
}
$(document).ready(function(){
//create initial sum
createSum();
// On "reset button" click, generate new random sum
$('button[type=reset]').click(createSum);
// On user input, check value
$( "#ans" ).keyup(checkInput);
});
子衿沉夜
相关分类