< a href = "#" onclick = "document.getElementById ('myform'). submit (); return false;" > Submit < / a >
< input type = "submit" value = "send" class = "link" / >
addEvent ( window , 'load' , windowLoad ) ;
/ * Cross-browser adding event handler * /
function addEvent ( obj , evType , fn ) {
if ( obj. addEventListener ) {
obj. addEventListener ( evType , fn , false ) ;
} else if ( obj. attachEvent ) {
obj. attachEvent ( 'on' + evType , fn ) ;
}
}
/ * Get the parent form for the element * /
function getParentForm ( obj ) {
while ( ( obj = obj. parentNode ) ) {
if ( obj. nodeName == 'FORM' ) {
break ;
}
}
return obj ;
}
/ * We are looking for all submit buttons with the link class and replacing them with links * /
function windowLoad ( ) {
var buttons = document. getElementsByTagName ( 'input' ) ;
for ( var i = 0 ; i < buttons. length ; i ++ ) {
if ( buttons [ i ] . getAttribute ( 'type' ) == 'submit' && buttons [ i ] . className == 'link' ) {
var link = document. createElement ( 'a' ) ;
link. appendChild ( document. createTextNode ( buttons [ i ] . getAttribute ( 'value' ) ) ) ;
link. setAttribute ( 'href' , '#' ) ;
addEvent ( link , 'click' , linkClick ) ;
var parent = buttons [ i ] . parentNode ;
parent. removeChild ( buttons [ i ] ) ;
parent. appendChild ( link ) ;
}
}
}
/ * We send the form by clicking on the link * /
function linkClick ( e ) {
var e = window. event || e ;
var target = e. target || e. srcElement ;
var parentForm = getParentForm ( target ) ;
parentForm. submit ( ) ;
if ( window. event ) { e. returnValue = false ; } else { e. preventDefault ( ) ; }
}
button
, and the span
needed in order to add underline text in Firefox.< button type = "submit" class = "link" > < span > Send < / span > < / button >
var buttons = document. getElementsByTagName ( 'button' ) ;
for ( var i = 0 ; i < buttons. length ; i ++ ) {
if ( buttons [ i ] . getAttribute ( 'type' ) == 'submit' && buttons [ i ] . className == 'link' ) {
var link = document. createElement ( 'a' ) ;
link. appendChild ( document. createTextNode ( buttons [ i ] . firstChild . firstChild . nodeValue ) ) ;
button .link {
/ * The first two properties are needed to remove indents in IE * /
overflow : visible ;
width : auto ;
/ * Remove indents * /
margin : 0 ;
padding : 0 ;
/ * Remove all button design elements * /
background : none ;
border : none ;
/ * Normal link cursor * /
cursor : pointer ;
}
/ * Link is usually underlined * /
button .link span {
color : # 00f ;
text-decoration : underline ;
}
-moz-user-select: text;
so that the text of the button can be highlighted, but I doubt the need.< form >
< input type = "text" name = "a" / >
< input type = "submit" id = "push-me" style = "display: none" / >
< / form >
< label for = "push-me" > fake submit < / label >
Source: https://habr.com/ru/post/65471/
All Articles