HTML中元素属性中ID和Name的区别

别再手动转格式了!用Java+LibreOffice命令行实现Word批量转PDF(附Docker部署避坑指南) 本文详细介绍了如何利用Java和LibreOffice命令行实现企业级Word批量转PDF的自动化解决方案,包括多线程优化、Docker化部署及常见问题排查。通过代码示例和实战经验,帮助开发者高效处理文档转换需求,提升工作效率并避免常见陷阱。 阅读详情

对于刚刚接触HTML源代码的朋友可能有这样一个疑惑:在一个表单元素中,我如果想用脚本确定某个具体元素,我既可以用他的NAME来索引这个对象,也可以加一个ID来索引它,那这两种方法究竟有什么区别呢?以下我们来具体探讨一下,鉴于本人水平有限,如有描述不当,恳请指教。

我们可以通过一段代码来分析一下其中的微妙差别:

<form method="post" action="" name="demoform">
<input type="text" name="oDemo" id=”oDemo2” value="DEMO" />
</form>



在IE浏览器里,我们可以通过多少方法来索引到这个文本框对象?(为区别起见,我们把NAME和ID设成了不同的值)
1. oDemo
2. demoform.oDemo
3. document.all.oDemo
4. document.all.demoform.oDemo
5. document.forms[0].oDemo
6. document.forms['demoform'].oDemo
7. document.forms['demoform'].childNodes[0]
8. document.forms['demoform'].elements[0]
9. document.getElementById('oDemo2')


以上9种索引方法在IE6里面全部通过返回值测试,不过值得注意的是最后一种:在IE6里,我把索引对象写成document.getElementById('oDemo'),浏览器也能正确索引到对象,真是可怕的容错性啊!!

接着问题来了,我们把这段代码放在Mozilla Firefox 1.0里再执行一次,只有第7种方法返回“undefined”,其他的方法可以正确索引到对象,不过由于第3、4种方法用到了document.all这个IE专有对象,FF1.0虽然返回了正确的值,不过却在控制台里发出了警告:警告:非标准的属性 document.all。请使用 W3C 的标准形式 document.getElementById() 。

接下来我们把HTML文本类型定义得严格一点,在源代码开头加上:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

使HTML文本按照HTML4.01标准去解析,在IE6里照样全部通过返回值测试,不过在Mozilla Firefox 1.0里麻烦就大了,第3、4种方法没有任何的返回值,而在控制台里发出了报错信息:错误: document.all has no properties ,而第7种方法依旧返回“undefined”。

小 结
NAME主要应用在交互式网页,表单提交给某个服务器端脚本后接收变处理量使用。从源代码的规范性和兼容性角度出发,如在客户端脚本里要索引某个对象,建议用document.getElementById()方法,尽量不要直接使用NAME的值,当然如果不考虑兼容性,以上9种方法都可以在IE里运行通过(IE5.0没测试过)。

附:测试源代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title></title> </head> <body> <form method="post" action="" name="demoform"> <input type="text" name="oDemo" value="DEMO" id="oDemo2" /><br /> <input type="button" value="oDemo" onclick="alert(oDemo.value)" /><br /> <input type="button" value="demoform.oDemo" onclick="alert(demoform.oDemo.value)" /><br /> <input type="button" value="document.all.oDemo" onclick="alert(document.all.oDemo.value)" /><br /> <input type="button" value="document.all.demoform.oDemo" onclick="alert(document.all.demoform.oDemo.value)" /><br /> <input type="button" value="document.forms[0].oDemo" onclick="alert(document.forms[0].oDemo.value)" /><br /> <input type="button" value="document.forms['demoform'].oDemo" onclick="alert(document.forms['demoform'].oDemo.value)" /><br /> <input type="button" value="document.forms['demoform'].childNodes[0]" onclick="alert(document.forms['demoform'].childNodes[0].value)" /><br /> <input type="button" value="document.forms['demoform'].elements[0]" onclick="alert(document.forms['demoform'].elements[0].value)" /><br /> <input type="button" value="document.getElementById('oDemo2')" onclick="alert(document.getElementById('oDemo2').value)" /><br /> </form> </body> </html>
 [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

ZYNQ裸机双网口通信实战:手把手教你用SDK和LWIP配置PS+PL以太网(附完整源码) 本文详细介绍了在ZYNQ裸机环境下实现双网口通信的全流程,包括硬件配置、LWIP协议栈优化及TCP通信实现。通过Vivado SDK和LWIP协议栈,开发者可以高效配置PS端内置网口与PL端扩展网口,提升嵌入式网络应用的灵活性和性能。附完整源码,助力快速开发。 阅读详情

相关推荐

MavLink协议入门

MAVLink是一个非常轻量化的开源的消息协议,用于无人机之间的通信以及无人机机载设备之间的通信。

ffffffeiyu的博客 2486

HTML常见元素

一个以空格分隔的元素的类名(classes)列表 它允许CSS和JavaScript通过类选择器或者DOM方法来选择和访问特定的元素。包含表示与其所属元素相关信息的文本 这些信息通常可以作为提示呈现给用户 但不是必须的。规定文档相关的配置信息(也称之为元数据) 包括文档的标题 引用的文档样式和脚本等。body元素里面的内容将是你在浏览器窗口中看到的东西,也就是网页的具体内容和结构。一般作为其他元素的父容器,把其他元素包住,代表一个整体。表示一个HTML文档的根 也被称为根元素。

m0_74355064的博客 1535

OTA(Over-The-Air)升级

OTA(Over-the-Air)是一种通过无线方式进行数据传输和更新的技术,通常用于电子设备(如智能手机、汽车、物联网设备等)的软件、固件或配置更新。OTA可以在设备与服务器之间进行远程传输,用户无需将设备接入电脑或进行有线操作。通过OTA,用户只需要通过Wi-Fi或移动网络连接,便能自动接收并安装最新的更新,而无需手动干预。OTA的优点是便捷和高效,能够确保设备随时保持最新状态,同时减少用户的操作负担。:如智能家居设备、路由器、汽车等硬件设备的固件更新。:确保设备上的应用保持最新版本。

weixin_50127894的博客 5082

获取element多选/单选的Name和ID

multiple 多选的属性 collapse-tags 多选的样式~ <el-select v-model="serveValue" placeholder="请选择" size='mini' multiple collapse-tags @change="selectContract"> <el-option v-for="...

weixin_44860425的博客 2706

Unity WebGL项目如何实现画布透明,完美融入网页背景(附.jslib文件与完整配置)

本文详细解析了Unity WebGL项目实现画布透明化的技术原理与实战步骤,从.jslib文件配置到前端框架集成,帮助开发者解决默认背景色问题,实现3D内容与网页设计的无缝融合。重点介绍了透明化核心机制、常见误区及React/Vue等现代框架中的最佳实践方案。

weixin_31896061的博客 307

避坑指南:用pygrib处理ERA5气象数据时遇到的5个典型问题

本文总结了使用pygrib库处理ERA5气象GRIB数据时常见的五个典型问题及解决方案,涵盖数据获取、内存管理、时间处理、空间插值和性能优化。重点针对气象数据插值这一核心挑战,提供了处理不规则网格、缺失值和跨日期变更线的实用代码示例与优化策略,帮助用户高效、稳定地完成气象数据分析工作。

weixin_28224217的博客 187

ElementName属性使用

今天在写自定义控件的时候,通过DependencyProperty注册了一个Page属性,同时在Main.page中使用ElementName绑定数据,代码如下: <local:QuickJumpGrid x:Name="QuickJumpGrid" Grid.Row="1" ...

dixiannie4307的博客 708

Qt视频播放器项目(打开文件,视频的播放与停止,进度条与视频进度绑定,调整音量,设置按钮图标,将槽函数与按钮绑定等功能)完整代码地址在末尾

【代码】Qt视频播放器项目。

分享计算机视觉,C++,网络摄像头研发,音视频开发,嵌入式等知识。 761

什么是HTML元素

HTML 文档由 HTML 元素定义。 HTML 元素以开始标签起始,以结束标签终止,元素的内容是开始标签与结束标签之间的内容。 HTML 文档由嵌套的 HTML 元素构成。 另外,没有内容的 HTML 元素被称为空元素。空元素是在开始标签中关闭的。 例如,&lt;br&gt; 就是没有关闭标签的空元素(&lt;br&gt; 标签定义换行)。 在开始标签中添加斜杠,比如 &lt;br /...

Afan_F的博客 1023

YOLOv11改进 | 细节涨点篇 | DySample一种最新的轻量化动态上采样算子(效果完爆CARAFE)

本文给大家带来的最新改进机制是一种号称超轻量级且有效的动态上采样器——DySample。与传统的基于内核的动态上采样器相比,DySample采用了一种基于点采样的方法,相比于以前的基于内核的动态上采样器,DySample具有更少的参数、浮点运算次数、GPU内存和延迟。此外,DySample在包括语义分割、目标检测、实例分割、全景分割和单目深度估计在内的五个预测任务中,性能均优于其他上采样器(截至目前最有效的上采样算子),

Snu77的博客 4226

《30天入门 SAP BTP 开发》教程的目录和使用说明,建议收藏

本教程分为两部分:第一部分为SAP BTP入门系列,包含从基础概念到操作步骤的系统性学习内容,建议零基础用户按顺序学习;第二部分为专题文章集合,涵盖SAP BTP的多个技术点,适合已有基础的用户按需查阅。教程包含账号申请、Global Account操作、Java应用开发、AI工具使用等丰富内容,同时解答常见问题并提供实战案例。所有文章均附带详细链接,便于读者系统学习或针对性查阅。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 4461

使用javascript通过className来获取元素

开始慢慢从JQUERY再转回到纯JS。。。代码//原理: 用document.getElementsByTagName('*');来获取所有元素,然后取得相同Class的元素。function getElementsByClassName(n) {    var classElements = [], allElements = document.getElementsByTagName('*')...

weixin_33755847的博客 138

33、嵌入式系统中的内存操作与实时操作系统

本博客详细探讨了嵌入式系统中的内存操作和实时操作系统(RTOS)的基本原理及应用。内容涵盖C、C++和MicroPython三种语言下的SDRAM读写示例,并结合机器人真空吸尘器的实际应用说明内存的使用场景。此外,还介绍了RTOS的核心概念、组件及其工作机制,包括任务、事件、互斥锁、信号量、队列等,并以FreeRTOS和Mbed OS为例展示了RTOS的配置与使用方法。最后,通过常见问题和实践项目加深对嵌入式系统开发的理解。

zz67890的博客 150

细说HTML元素的ID和Name属性的区别

id与name的作用,作为标签的标识符,基本上是一样的.name是老方法,id是在name基础上发明的,后来才有的,"现代化"一点,用的范围广一点. 中的name原来(刚发明时)就是用于本页揿一下转向过去用的. 除 BASE, HEAD, HTML, META, SCRI

hoppboy的专栏 2401

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

简述HTML元素的ID和Name属性的区别

    可以说几乎每个做过Web开发的人都问过,到底元素的ID和Name有什么区别阿?为什么有了ID还要有Name呢?! 而同样我们也可以得到最classical的答案:ID就像是一个人的身份证号码,而Name就像是他的名字,ID显然是唯一的,而Name是可以重复的。    上周我也遇到了ID和Name的问题,在页面里输入了一个input type="hidden",只写了一个ID=SliceI

wiregate的专栏 1486

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

HTML元素的ID和Name属性的区别

原作者:http://www.verydemo.com/demo_c101_i37329.html 今天對 有點疑惑, 加上#表示一個錨,後面跟上13,就會跳到本頁面的13的位置,而這個13就是 Name屬性值。怎麼不 是ID值呢???所以查了下ID 和Name的區別,特記錄 最classical的答案:ID就像是一个人的身份证号码,而Name就像是他的名字,ID显然是唯一的,而Na

neveremind158的专栏 443

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

转: 细说HTML元素的ID和Name属性的区别

可以说几乎每个做过Web开发的人都问过,到底元素的ID和Name有什么区别阿?为什么有了ID还要有Name呢?! 而同样我们也可以得到最classical的答案:ID就像是一个人的身份证号码,而Name就像是他的名字,ID显然是唯一的,而Name是可以重复的。 上周我也遇到了ID和Name的问题,在页面里输入了一个input type="hidden",只写了一个ID='SliceI...

weixin_30701575的博客 152

细说HTML元素的ID和Name属性的区别[转帖]

可以说几乎每个做过Web开发的人都问过,到底元素的ID和Name有什么区别阿?为什么有了ID还要有Name呢?! 而同样我们也可以得到最classical的答案:ID就像是一个人的身份证号码,而Name就像是他的名字,ID显然是唯一的,而Name是可以重复的。 上周我也遇到了ID和Name的问题,在页面里输入了一个input type="hidden",只写了一个ID='SliceInf...

weixin_30385925的博客 183

Html+Css__HTML元素的ID和Name属性的区别

HTML元素的ID和Name属性的区别 使用的范围: 除了一些特殊符号(等)都有的,但name 属性一般都用在表单元素里,用来提交数据给后台! 定位html都用id的 作用的不同: ID就像是一个人的身份证号码,而Name就像是他的名字,ID显然是唯一的,而Name是可以重复的今天對 有點疑惑, 加上#表示一個錨,後面跟上13,就會跳到本頁面的13的位置,而這個1

迎难而上 1951

细说HTML元素的ID和Name属性的区别(转)

<!-- p {margin-bottom:0.21cm} --> 细说HTML元素的ID和Name属性的区别 可以说几乎每个做过Web开发的人都问过,到底元素的ID和Name有什么区别阿?为什么有了ID还要有Name呢?!而同样我们也可以得到最class

centre10的专栏 795
上一篇: Struts2:struts.xml常用配置解析3
下一篇: HTML中ID与Name的区别2
ddBee
博客等级 码龄18年 9粉丝 7原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值