一般有两种方法:一是通过innerHTML来添加元素;二是通过appendChild()来添加。

  区别是:前者添加后,不会立即生效;而后者则会立即生效。

  例子:

  静态页面:

js 动态创建网页对象<html>
js 动态创建网页对象    
<head>
js 动态创建网页对象        
<script type="text/javascript">
html>

  采用js动态添加——通过innerHTML:

js 动态创建网页对象<html>
js 动态创建网页对象    
<head>
js 动态创建网页对象        
<script type="text/javascript">
html>

  动态创建网页元素——通过createElement()和appendChild():

js 动态创建网页对象<html>
js 动态创建网页对象    
<head>
js 动态创建网页对象        
<script type="text/javascript">
html>

 

  这3种情况下,第二种情况,即通过innerHTML的方式来动态创建网页元素时,被动态创建的表单form无法提交,而第三种情况,即通过createElement()和

appendChild()的方式动态创建的表单form便可以提交:submit()。

相关文章:

  • 2021-07-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
猜你喜欢
  • 2021-11-18
  • 2021-10-31
  • 2021-06-03
  • 2022-12-23
  • 2021-04-26
相关资源
相似解决方案