当想要用" http://example.com/#foo"方法引用网页的某些部分时,应该使用
<h1><a name="foo"/>Foo Title</h1>
Run Code Online (Sandbox Code Playgroud)
要么
<h1 id="foo">Foo Title</h1>
Run Code Online (Sandbox Code Playgroud)
他们都工作,但他们是平等的,还是他们有语义差异?
id和name属性有什么区别?它们似乎都与提供标识符的目的相同.
我想知道(特别是关于HTML表单)是否有必要或鼓励使用两者都是出于任何原因.
我是JavaScript的新手,试图在表单验证上找到自己的方式.我一直在阅读书籍和在线教程,我在网上发现了以下代码,在我看来,这是非常优雅和可维护的.不幸的是,我在JavaScript方面的技能还不足以理解一切.我在这里请求您帮助理解定义的不同功能.
我还想在一个事件(onSubmit事件)上调用InstantValidation函数,在一个独立的.js文件中调用它(基于事件监听器),所以你能帮我调用一下这个函数吗?
这是代码:
<html>
<body>
<form id="myform" action="#" method="get">
<fieldset>
<legend><strong>Add your comment</strong></legend>
<p>
<label for="author">Name <abbr title="Required">*</abbr></label>
<input name="author" id="author" value=""
required="required" aria-required="true"
pattern="^([- \w\d\u00c0-\u024f]+)$"
title="Your name (no special characters, diacritics are okay)"
type="text" spellcheck="false" size="20" />
</p>
<p>
<label for="email">Email <abbr title="Required">*</abbr></label>
<input name="email" id="email" value=""
required="required" aria-required="true"
pattern="^(([-\w\d]+)(\.[-\w\d]+)*@([-\w\d]+)(\.[-\w\d]+)*(\.([a-zA-Z]{2,5}|[\d]{1,3})){1,2})$"
title="Your email address"
type="email" spellcheck="false" size="30" />
</p>
<p>
<label for="website">Website</label>
<input name="website" id="website" value=""
pattern="^(http[s]?:\/\/)?([-\w\d]+)(\.[-\w\d]+)*(\.([a-zA-Z]{2,5}|[\d]{1,3})){1,2}(\/([-~%\.\(\)\w\d]*\/*)*(#[-\w\d]+)?)?$"
title="Your website address"
type="url" spellcheck="false" size="30" />
</p>
<p>
<label for="text">Comment <abbr …Run Code Online (Sandbox Code Playgroud) 这是表格:
<form name=fname ...
<input name=iname value="" ...
Run Code Online (Sandbox Code Playgroud)
这个javascript函数获取输入的值:
var val = document.fname.iname.value;
Run Code Online (Sandbox Code Playgroud)
这是合法的吗?我以为你必须这样做getElementsByName.它有效,只是我从未见过有人这样做过.这是恰好恰好工作的那件事之一吗?现在呢?
If the purpose of the name attribute in HTML forms only to reference the element such as input, why couldn't we have simply used id or class attributes? Was there some not so obvious reasoning behind creating the name attribute.
.....html
Name: <input type="text" name="fullname"><br>
.....
Run Code Online (Sandbox Code Playgroud) 我有以下表格:
<form id="formId">
<!-- some tags -->
<div>
<!-- some other divs or something else -->
<input type="radio" onclick="handler(this) />
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
函数处理程序的位置如下:
var handler = function(elem){
init();
var clicked = //here should be form id
//other staff
};
Run Code Online (Sandbox Code Playgroud)
如何获取随附表格的ID?假设网页上只有一个表单.
我正在寻找pure-js以及jQuery解决方案.
html ×5
javascript ×4
attributes ×1
dom ×1
forms ×1
function ×1
handler ×1
html5 ×1
hyperlink ×1
jquery ×1
php ×1
validation ×1