用新的ID替换表单ID? [英] replace form id with new id?

查看:86
本文介绍了用新的ID替换表单ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用新ID替换表单标签ID?

How to replace form tag id with new id?

  <form method="post" action="contactus.aspx" id="ctl01">

id="ctl01"替换为id="validForm"

看起来像ctl01 id由代码生成.到我们更改ID名称时,"crl01"尚不可用.页面加载后如何处理?

look like ctl01 id generating by code. by the time we changing id name, 'crl01` is not available yet. How to handle after page loaded?

推荐答案

获取Java元素并进行更改.

Get the element in Javascript and change it.

document.getElementById('ctl01').id = 'validForm';

您也可以使用jQuery.attr();.

$('#ctl01').attr('id','validForm');

要等待DOM加载,请使用以下命令:

To wait for the DOM to load, use this:

$(document).ready({
  //DOM is ready
});

通用语法也是这样:

$(function() {
  //DOM is ready
});

还有其他方法,但这是最常见的方法.

There are also other ways, but these are the most common.

这篇关于用新的ID替换表单ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆