如何获得div id值 [英] How to get div id value

查看:79
本文介绍了如何获得div id值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取div id值.获取id后,我想要在该div上附加一些文本字段.实际上我正在获取div id值.但是文本字段未附加到div.它正在擦除以前的数据并且它仅添加一个字段.我想添加3个文本字段.

How to get the div id value.After getting the id i want append some text-fields to that div.Actually i am getting the div id value.But text-fields are not appending to div.It is erasing previous data and it is adding only one field.I want to add 3 text-fields.

推荐答案

如何获取div id值
如果div具有"runat = server",则可以通过以下方式访问该ID:
How to get the div id value
If div has ''runat=server'' then the ID can be accessed as:
// Access the div with it's ClientID
var divToAccess = document.getElementById("<%=whateverIsDivId.ClientID%>");



如果div是不带runat = server的常规HTML控件,



If div is a general HTML control without runat=server,

// Access the div with it's ID
var divToAccess = document.getElementById("whateverIsDivId");


我建​​议使用JQuery
I suggest JQuery
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"

 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title>Untitled Page</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"

	 type="text/javascript"></script>
    <script type="text/javascript">
        function setFields() {


(' #divResults').html(


这篇关于如何获得div id值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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