javascript 更改提交按钮的图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4836478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 15:02:36  来源:igfitidea点击:

Change image of Submit button

phpjavascripthtmlforms

提问by Ivan Reuben Ramos Muit

I wanted to Change the submit button of my form.I manage to do it and Its quite easy however the code breaks. When i fixed the code. The submit button changes back to its default image and it said submit query which i did not initialize. I have not figured out how to fix it since then. Which is weird.

我想更改表单的提交按钮。我设法做到了,但是代码中断了,这很容易。当我修复代码时。提交按钮变回其默认图像,并显示我未初始化的提交查询。从那以后我一直没有想出如何解决它。这很奇怪。

<?Php
    echo "<div style='text-align:right'>
       <form action='upd2.php' method='POST'>
       <Table border='0' align='right'>
       <tr>
        <td ><font size='-3'>ID Search</font></td>
        <td rowspan =2><input name='image' type='image' id='SUBMIT' src='images/_Images_buttons_search_button.jpg'></td>
       </tr>
       <tr>
        <td><input name='ID_NO' type='text' id='ID_NO'></td>
       </tr>
       </table><br>
       </FORM> </div>";
?>

I pass it on to this

我把它传递给这个

<?php
    print "<H2>Update User Info</H2>";

    $ID_NO   = clean($_POST['ID_NO']);
 $_SESSION["ID_NO"] = $ID_NO;
     if (isset($_POST['image'])) {
        $result = mysql_query("SELECT * FROM user_info WHERE ID_NO = '$ID_NO'");
        if(!mysql_num_rows($result)) {
            print "<BR><BR>There is no such User with a User Number of $ID_NO <BR><A HREF ='UpdateUser.php'>Go Back</A>";
     exit();
        }
        else {
            $row_array = mysql_fetch_array($result, MYSQL_ASSOC);
?>

however, it does not work(the variable wasnt able to get it). I should have change "image" with "SUBMIT". But if I do that, then the image would be in default.

但是,它不起作用(变量无法获得它)。我应该用“提交”更改“图像”。但如果我这样做,那么图像将处于默认状态。

so in short

所以简而言之

type='SUBMIT' -> i get to make the code work but default picture.

type='SUBMIT' -> 我让代码工作但默认图片。

type='image' -> i get the nice image but the code wont work.

type='image' -> 我得到了漂亮的图像,但代码不起作用。

回答by GolezTrol

You can just set the background image of the button using css.

您可以使用 css 设置按钮的背景图像。

<input type="submit" style="background-image: url(bgb.png);" />

(Better to use separate style sheet off course)

(当然最好使用单独的样式表)