js循环function函数问题

来源:百度知道 编辑:UC知道 时间:2024/05/17 07:33:32
下面这段js循环出不来,为了实现下面的功能,求高手解决下

<input type="submit" name="Submit1" value="提交" onclick="button1('button11')"/>
<input type="submit" name="Submit2" value="提交" onclick="button2('button21')"/>
<input type="submit" name="Submit3" value="提交" onclick="button3('button31')"/>
<input type="submit" name="Submit4" value="提交" onclick="button4('button41')"/>
<input type="submit" name="Submit5" value="提交" onclick="button5('button51')"/>
<br>
<input type="text" name="textfield" />

<script>
for (i=1;i<6;i++)
{ var obj = eval("button"+i);
function obj(xiao)
{
document.getElementById('textfi

你为什么要用那么多方法呢?
要实现你的功能 调用同一方法就好啊? 不但不长 还简单。

<input type="button" name="Submit1" value="提交" onclick="button('button11')"/>
<input type="button" name="Submit2" value="提交" onclick="button('button21')"/>
<input type="button" name="Submit3" value="提交" onclick="button('button31')"/>
<input type="button" name="Submit4" value="提交" onclick="button('button41')"/>
<input type="button" name="Submit5" value="提交" onclick="button('button51')"/>
<br>
<input type="text" name="textfield" />

<script>

function button(xiao)
{
document.getElementById('textfield').value=xiao
}

</scr