Domanda

Ho ottenuto un'immagine con i collegamenti a un'altra pagina usando < a href = " ... " > < img ... > & Lt; / a >.

Come posso fare per pubblicare un post come se fosse un pulsante < input type = " submit " ... > ?

È stato utile?

Soluzione

<input type="image" name="your_image_name" src="your_image_url.png" />

Questo invierà i valori your_image_name.x e your_image_name.y quando invia il modulo, che sono le coordinate xey della posizione in cui l'utente ha fatto clic sull'immagine .

Altri suggerimenti

Approvazione più generica utilizzando libreria JQuery più vicino () e submit () pulsanti. Qui non è necessario specificare quale modulo desideri inviare, invia il modulo in cui si trova.

<a href="#" onclick="$(this).closest('form').submit()">Submit Link</a>

Sembra che tu stia cercando di utilizzare un'immagine per inviare un modulo ... in tal caso, utilizza < input type = " image " src = " ... " >

Se vuoi davvero usare un anchor, devi usare javascript:

< a href = " # " onclick = " document.forms [ 'myFormName'] presentare ().; return false; " > ... < / a >

input type = image lo farà per te.

Non testato / potrebbe essere migliore:

<form action="page-you're-submitting-to.html" method="POST">
    <a href="#" onclick="document.forms[0].submit();return false;"><img src="whatever.jpg" /></a>
</form>
 <html>

 <?php

 echo <*>POST['c']." | ".<*>POST['d']." | ".<*>POST['e'];

 ?>

 <form action="test.php" method="POST">
      <input type="hidden" name="c" value="toto98">
      <input type="hidden" name="d" value="toto97">
      <input type="hidden" name="e" value="toto aaaaaaaaaaaaaaaaaaaa">

      <a href="" onclick="document.forms[0].submit();return false;">Click</a> 
 </form>

</html>


So easy.




So easy.

Quello che potrebbe essere un'aggiunta utile a questo è la possibilità di cambiare il post-url dal pulsante extra in modo da poter postare su diversi URL con pulsanti diversi. Ciò può essere ottenuto impostando la proprietà 'azione' del modulo. Ecco il codice per questo quando si utilizza jQuery:

$('#[href button name]').click(function(e) {
    e.preventDefault();
    $('#[form name]').attr('action', 'alternateurl.php');
    $('#[form name]').submit();
});

L'attributo action presenta alcuni problemi con le versioni precedenti di jQuery, ma al più tardi sarai a posto.

Qualcosa come questa pagina ?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>BSO Communication</title>

<style type="text/css">
.submit {
    border : 0;
    background : url(ok.gif) left top no-repeat;
    height : 24px;
    width : 24px;
    cursor : pointer;
    text-indent : -9999px;
}
html:first-child .submit {
    padding-left : 1000px;
}
</style>
<!--[if IE]>
<style type="text/css">
.submit {
    text-indent : 0;
    color : expression(this.value = '');
}
</style>
<![endif]-->
</head>

<body>
    <h1>Display input submit as image with CSS</h1>

    <p>Take a look at <a href="/2007/07/26/afficher-un-input-submit-comme-une-image/">the related article</a> (in french).</p>
    <form action="" method="get">
        <fieldset>
            <legend>Some form</legend>
            <p class="field">
                <label for="input">Some value</label>

                <input type="text" id="input" name="value" />
                <input type="submit" class="submit" />
            </p>
        </fieldset>
    </form>

    <hr />
    <p>This page is part of the <a href="http://www.bsohq.fr">BSO Communication blog</a>.</p>

</body>
</html>

Non dimenticare il pulsante "PULSANTE" elemento che può gestire un po 'più di HTML all'interno ...

Sostituiamo sempre il pulsante di invio con questo nei moduli:

<form method="post" action="whatever.asp">
<input type=...n

<input type="image" name="Submit" src="/graphics/continue.gif" align="middle" border="0" alt="Continue">
</form>

Facendo clic sull'immagine si invia il modulo. Spero che ti aiuti!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top