snandy

如下

<!DOCTYPE html>
<html>
  <head>
	<meta charset="utf-8">
	<title>有name为action的表单元素时取form的属性action杯具了</title>
  </head>  
  <body>
  	<form name="mform" action="http://xxx">
		<input type="radio" name="action" value="1"/> 动作1
		<input type="radio" name="action" value="2"/> 动作2
		<input type="radio" name="action" value="3"/> 动作3
		<br/>
		<input type="submit" value="提交"/>
	</form>
	<script type="text/javascript">		
		document.mform.onsubmit = function(){
			alert(this.action);
			return false;
		}
	</script>
  </body>
</html>

后台经常根据动作(action)来判断要调用的逻辑。呃,这个词...

这时form.action会优先取到表单元素而非form的属性action。所有浏览器中都一致。

这时获取form的属性使用this.getAttribute是安全的。


需注意..

分类:

技术点:

相关文章:

  • 2021-11-12
  • 2021-09-19
  • 2021-09-29
  • 2021-09-09
  • 2022-12-23
  • 2021-09-19
  • 2021-11-12
  • 2021-12-27
猜你喜欢
  • 2021-08-06
  • 2021-12-15
  • 2022-12-23
  • 2021-09-19
  • 2021-09-29
  • 2021-09-19
相关资源
相似解决方案