-1

嗨,我正在尝试右对齐由 JS 创建的“捐赠”按钮,如下面的代码所示,

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MentorMentee.master.cs" Inherits="MentorMentee.MentorMentee" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <link href="style/style.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="head" runat="server"> 

    </asp:ContentPlaceHolder>

</head>
<body>
    <form id="form1" runat="server" action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <div id="main">
    <header>
      <div id="logo">
        <div id="logo_text">
          <!-- class="logo_colour", allows you to change the colour of the text -->
            <h1><span>M</span></h1>  
            <script type="text/javascript">
    function Donate()
{
    var myform = document.createElement("form");
    myform.action = "https://www.paypal.com/cgi-bin/webscr";
    myform.method = "post";
    myform.target = "_blank";

    var image = document.createElement("input");
    image.type = "image";
    image.src = "https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif";
    image.border = "0";
    image.name = "submit";
    image.alt="PayPal - The safer, easier way to pay online!";

    //Most probably this can be skipped, but I left it in here since it was present in the generated code
    var pixel = document.createElement("image");
    pixel.border = "0";
    pixel.alt="";
    pixel.src = "https://www.paypalobjects.com/en_US/i/scr/pixel.gif";
    pixel.width = "1";
    pixel.height = "1";


    myform.appendChild(image);


    myform.submit();
}
    </script>        
      </div>
      <nav>
        <asp:ContentPlaceHolder ID="HeaderContent" runat="server">

        </asp:ContentPlaceHolder>
        </nav>
        </div>
        </header>
        <div id="site_content">
        <div class="content">
                <asp:ContentPlaceHolder ID="MainContent" runat="server">
                </asp:ContentPlaceHolder>
            </div>
        </div>
    </div>
<img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif"
border="0"
alt="PayPal - The safer, easier way to pay online!"
onclick="javascript:Donate();"
style="cursor:pointer;"/>
    </form>
</body>
</html>

但我愿意把它放在我正在做的同一行,

<h1><span>M</span></h1>
4

1 回答 1

0

您可以将 ID 添加到您的图像标签并使用以下代码:

var myImageId = document.getElementById("IMAGE_ID");
document.getElementById("myButton").onclick = function () {myImageId.style.float = “left”;};

并且您可以设置任何属性,例如: padding , margin ,...来设置左侧的图像取决于您的页面

于 2013-01-22T07:40:08.367 回答