如何使用 JavaScript 将图像右对齐
How to align image to right using JavaScript?
嗨,我正在尝试右对齐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>
您可以将
ID 添加到图像标记并使用以下代码:
var myImageId = document.getElementById("IMAGE_ID");
document.getElementById("myButton").onclick = function () {myImageId.style.float = “left”;};
您可以设置任何属性,例如:填充,边距,...在左侧设置图像取决于您的页面
相关文章:
- typeahead下拉结果向右对齐-向右拉
- Div向右对齐,并根据右侧的其他Div更改x位置
- 将 HTML 选项卡右对齐
- Css浮动:右100%高度,图像底部对齐
- 文本相对于 SVG 中的父项 G 右对齐
- 脸书照片/图像垂直对齐
- 将彩色带置于图像/标签+图像/文本对齐方式之上->JavaScript Titanium移动应用程序
- 如何在离子列表中显示两个右对齐的图标
- 调整窗口大小时向右对齐
- 引导程序下拉右对齐失败
- 增强Showdown.js表代码,使其支持表标题的左/右对齐
- 表格图像表格对齐问题
- 将一个子对象左对齐,将第二个子对象右对齐extjs
- 文本和图像没有对齐
- 背景-图像中心对齐,边距:0,自动带滚动条
- 如何右对齐/调整引导下拉菜单项
- 谷歌+按钮删除自由空间/边距向右|对齐到右
- jQueryUI 对话框隐藏关闭 (X) 按钮,如果标题包含右对齐的文本.我该如何解决这个问题
- Extjs空文本向右对齐
- 如何使用 JavaScript 将图像右对齐