< a href…>…< / a>から送信する方法リンク?
-
07-07-2019 - |
質問
< a href =" ...">を使用して別のページへのリンクを含む画像を取得しました。 < img ...> < / a>
。
ボタンのような投稿を作成するにはどうすればよいですか< input type =" submit" ...>
?
解決
<input type="image" name="your_image_name" src="your_image_url.png" />
これは、フォームを送信するときに your_image_name.x
および your_image_name.y
の値を送信します。これは、ユーザーが画像をクリックした位置のxおよびy座標です。 。
他のヒント
画像を使用してフォームを送信しようとしているようです...その場合は
&lt; input type =&quot; image&quot; src =&quot; ...&quot;&gt;
本当にアンカーを使用する場合は、javascriptを使用する必要があります。
&lt; a href =&quot;#&quot; onclick =&quot; document.forms ['myFormName']。submit(); return false;&quot;&gt; ...&lt; / a&gt;
input type = image が自動的に処理します。
未テスト/改善される可能性があります:
<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.
これに便利な追加機能は、追加のボタンからpost-urlを変更して、異なるボタンで異なるURLに投稿できるようにすることです。これは、フォームの「アクション」プロパティを設定することで実現できます。 jQueryを使用する場合のコードは次のとおりです。
$('#[href button name]').click(function(e) {
e.preventDefault();
$('#[form name]').attr('action', 'alternateurl.php');
$('#[form name]').submit();
});
アクション属性には、古いjQueryバージョンでいくつかの問題がありますが、最新バージョンでは問題ありません。
このページのようなもの?
<!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>
「ボタン」を忘れないでください。内部でHTMLを処理できる要素...
フォームの送信ボタンを常にこれに置き換えます:
<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>
画像をクリックすると、フォームが送信されます。役に立てば幸いです!