function ingredientsHover() {
document.getElementById('ingredients').firstElementChild.firstElementChild.style.fontSize = '300%';
}
function ingredientsNormal() {
document.getElementById('ingredients').firstElementChild.firstElementChild.style.fontSize = '100%';
// document.write("Normal");
}
function preparationHover() {
document.getElementById('preparation').firstElementChild.firstElementChild.style.fontSize = '300%';
}
function preparationNormal() {
document.getElementById('preparation').firstElementChild.firstElementChild.style.fontSize = '100%';
}
答案 0 :(得分:0)
创建一个接受元素ID和fontSize值的单个函数。在函数内部,将元素id作为变量传递给document.getElementById
function ingredientsStyling(elem, styleVal) {
document.getElementById(elem).firstElementChild.firstElementChild.style.fontSize = styleVal;
}
ingredientsStyling('ingredients', '300%');