<html>
<body>
<form action="">
<script>
for(i=0;i<50;i++)
{
document.writeln("<input type='button' value ='"+i+"' onclick='clicked(i)'/>");
}
function clicked(Number x)
{
alert("selected:" +x);
}
</script>
</form>
</body>
</html>
我想知道在此代码中选择了哪个按钮如何执行,请有人帮助我
答案 0 :(得分:0)
在此处查看如何在JavaScript中声明函数: https://www.w3schools.com/js/js_function_parameters.asp
答案 1 :(得分:0)
我希望这对你有用
<!DOCTYPE html>
<html>
<body>
<p>Click the button to know its value.</p>
<button value="1" onclick="myFunction(this.value)">A</button>
<button value="2" onclick="myFunction(this.value)">B</button>
<button value="3" onclick="myFunction(this.value)">C</button>
<script>
function myFunction(value) {
alert(value);
}
</script>
</body>
</html>
答案 2 :(得分:-1)
您可以在此方法中执行相同的操作:
for (i = 0; i < 10; i++) {
document.writeln("<input type='button' value='" + i + "' onclick='alert(this.value)'>");
}
&#13;