问题
I am checking my HTML code with Amaya.
I have an error on this line:
<input style="vertical-align:bottom;" type="text" id="doi_id" onkeydown="if (event.keyCode == 13) return false;" onpaste="parsePIIfromDOI();"/>
And for the onpaste, I am getting "Invalid attribute "onpaste"(removed when saving)" error.
I don't know why? Thank you very much for your help.
回答1:
http://reference.sitepoint.com/html/extended-event-attributes/onpaste
"Non-standard event defined by Microsoft for use in Internet Explorer. May work in some other browsers but cannot be reliably used. Compatibility for this non-standard attribute not tested."
回答2:
The Amaya editor performs a syntax check using a document type definition, and its built-in repertoire includes only doctypes that do not allow the onpaste
attribute. That’s why you get the error message.
There’s probably no way around this message in Amaya. You can use Tools → Change doctype → Remove the doctype or, better, manually change, in Show Source mode, the doctype declaration to <!doctype html>
, the HTML5 doctype. But Amaya still keeps checking against the specification it regards as the correct one.
Amaya is an editor (and a testbed browser), not a checker. Use a validator to check your syntax. Then you can use <!doctype html>
to specify HTML5. Beware that HTML5 has some oddities, and contrary to popular misconceptions, it is not a pure extension of HTML 4.01. And apparently because Amaya decides to remove the attribute, you would need to use a different editor.
Whether onpaste
is useful and safe to use is a different question.
Update (July 2018): Over the years that have passed, onpaste
has not become part of official HTML, so a validator issues an error message about it. Yet, support appears to appear e.g. in Chrome. If you need to avoid validation errors (or your editor removes an onpaste
attribute), use JavaScript to assign a value to the onpaste
property of the element node instead of using an attribute in HTML markup.
来源:https://stackoverflow.com/questions/12367417/html-onpaste-dosomething-as-invalid-attribute