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-12-28
  • 2021-10-28
  • 2021-07-14
  • 2021-07-05
  • 2022-02-16
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2021-08-01
  • 2021-12-24
  • 2021-10-10
  • 2021-09-11
相关资源
相似解决方案