我有以下代码:
<html>
<head>
<link rel="stylesheet" href ="java.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function meal(){
var checkboxes = document.getElementsByName('checkboxes');
var i=0;
var j=0;
var dish = [
["Boiled eggs","Eggs"],
["BLT Sandwich","Bacon"],
["BLT Sandwich","Lettuce"],
["BLT Sandwich","Tomato"],
["BLT Sandwich","Bread"],
["American Breakfast","Eggs"],
["American Breakfast","Bacon"],
["American Breakfast","Bread"],
["French Fries","Patatoes"]
];
var content = "";
for (i=0 ; i < dish.length; i++){
for(j=0 ; j< checkboxes.length; j++){
if ((dish[i][1] == checkboxes[j].value)&&(checkboxes[j].checked)){
content+= dish[i][0] + '<br>';
}
}
}
document.getElementById("result").innerHTML = content;
}
</script>
</head>
<body>
<div id="big_one">
<header id="Welcome">
<h1>Welcome</h1>
</header>
<div id= "new_div">
<section id="check_boxes">
<article >
<header>
<form name="ingredient">
<input type="checkbox" name="checkboxes" value="Eggs"> Eggs <br>
<input type="checkbox" name="checkboxes" value="Bacon"> Bacon <br>
<input type="checkbox" name="checkboxes" value="Lettuce"> Lettuce <br>
<input type="checkbox" name="checkboxes" value="Tomato"> Tomato <br>
<input type="checkbox" name="checkboxes" value="Bread"> Bread <br>
<input type="checkbox" name="checkboxes" value="Patatoes"> Patatoes </br>
</form>
</header>
</article>
<article >
<header>
<form name="Button">
<input type="button" name="Check" onClick="meal()" value="Search">
</form>
</header>
</article>
</section>
<div id="result">
</div>
</div>
<footer id="the_footer">
Copyright © Dejan Ivanov
</footer>
</div>
</body>
</html>
这段代码的想法是:如果我选择“eggs”只显示菜“煮鸡蛋”,如果我选择“鸡蛋”、“培根”和“面包”显示菜“煮鸡蛋”和“美式早餐” , 但节目给我看“煮鸡蛋”、两次“BLT 三明治”和三次“美式早餐”
For example if the known recipes are:
Boiled eggs -> Eggs
BLT Sandwich -> Bacon, Lettuce, Tomato, Bread
American Breakfast -> Eggs, Bacon, Bread
and the available ingredients are:
Bread, Eggs and Bacon
The search result should be:
Boiled eggs
American Breakfast
你能帮我在Javascript代码中解决这个问题吗?