页面循环多个表单出错

日出
  • 22

<form name="favform" action="javascript:void(0)" onsubmit="return gotofav()">
<input type="txt" name="fav" value="-1.933227,115.807851"><input type="submit" value="go" /></form>

上面这个代码会从数据库循环输出很多,导致页面表单重复无法运行,提示
;Uncaught TypeError: Cannot read property 'value' of undefined

下面是js函数
function gotofav(){Map.flyTo(document.favform.fav.value.split(','));

请问怎么解决。谢谢。

就是这样就不能运行;多个表单在一页:
<form name="favform" action="javascript:void(0)" onsubmit="return gotofav()">
<input type="txt" name="fav" value="-1.933227,115.807851"><input type="submit" value="go" /></form>

<form name="favform" action="javascript:void(0)" onsubmit="return gotofav()">
<input type="txt" name="fav" value="-1.933227,115.807851"><input type="submit" value="go" /></form>

<form name="favform" action="javascript:void(0)" onsubmit="return gotofav()">
<input type="txt" name="fav" value="-1.933227,115.807851"><input type="submit" value="go" /></form>

回复
阅读 187
1 个回答
✓ 已被采纳
<form name="favform" action="javascript:void(0)" onsubmit="return gotofav(this)">
<input type="txt" name="fav" value="-1.933227,115.807851"><input type="submit" value="go" /></form>

<form name="favform" action="javascript:void(0)" onsubmit="return gotofav(this)">
<input type="txt" name="fav" value="-1.933227,115.807851"><input type="submit" value="go" /></form>

<form name="favform" action="javascript:void(0)" onsubmit="return gotofav(this)">
<input type="txt" name="fav" value="-1.933227,115.807851"><input type="submit" value="go" /></form>
function gotofav(obj){Map.flyTo(obj.fav.value.split(','))};

document.favform多个form返回的是个数组.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
你知道吗?

宣传栏