我有一个非常简单的HTML页面,其中包含不同的复选框,我希望选择其中的三个并显示下面的产品名称。HTML选择三个不同的复选框并显示它们
我需要什么,例如,如果我选择复选框Nº1,3和4,我需要看到:
选择3个香水
- 香水一生之
- 热带
- Eau d'Issey2
但是每次点击一个复选框,我会得到三个相同的结果。任何人都可以帮助我吗? 我的代码如下...
非常感谢!
<html>
<head>
<script language="javascript" type="text/javascript">
function exefunction(me) {
var check = document.getElementById(me.id).checked;
var checked_value;
var str1 = "product";
var n = 1;
for (i = 0; i <= 2; i++) {
if (check) {
checked_value = document.getElementById(me.id).name
document.getElementById("product" + n).innerHTML = checked_value;
n++;
}
}
}
</script>
</head>
<body>
<p>1.
<input type="checkbox" id="1" name="Eau d'Issey" title="Select All" onclick="exefunction(this);">
<p>2.
<input type="checkbox" id="2" name="Fahrenheit" title="Select All" onclick="exefunction(this);">
<p>3.
<input type="checkbox" id="3" name="Tropical" title="Select All" onclick="exefunction(this);">
<p>4.
<input type="checkbox" id="4" name="Eau d'Issey2" title="Select All" onclick="exefunction(this);">
<p>5.
<input type="checkbox" id="5" name="Fahrenheit2" title="Select All" onclick="exefunction(this);">
<p>6.
<input type="checkbox" id="6" name="Tropical2" title="Select All" onclick="exefunction(this);">
<p>Choose 3 perfumes.</p>
<h3>1: </h3>
<p id="product1"></p>
<h3>2: </h3>
<p id="product2"></p>
<h3>3: </h3>
<p id="product3"></p>
</body>
</html>
请在代码编辑器使用整齐按钮。 – Roope