سؤال

حصلت على صورة تكون بها روابط إلى صفحة أخرى باستخدام <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 للموضع الذي نقره المستخدم على الصورة.

نصائح أخرى

مزيد من الموافقة العامة باستخدام jQuery مكتبة الأقرب() و إرسال() أزرار. هنا لا يتعين عليك تحديد نموذج Whitch الذي تريد إرساله ، ويقدم النموذج الموجود فيه.

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

يبدو أنك تحاول استخدام صورة لإرسال نموذج ... في هذه الحالة الاستخدام<input type="image" src="...">

إذا كنت ترغب حقًا في استخدام مرساة ، فعليك استخدام JavaScript:

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

نوع الإدخال = الصورة سأفعل ذلك من أجلك.

لم يتم اختباره / يمكن أن يكون أفضل:

<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();
});

لدى Action-Attribute بعض المشكلات مع إصدارات 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>

النقر فوق الصورة يقدم النموذج. امل ان يساعد!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top