javascript - 如何将两个按钮放在同一水平线上?

标签 javascript html css

我正在用 JavaScript 制作一个 HTML 表单并且它可以工作,但是两个按钮:取消和提交位于不同的行上(一个在另一个之上)。如何使它们水平对齐?

这是我的代码:

var new_comment_form = "<form id='add_comment' method='post'><textarea name='problem_comment' cols=60 rows=6 id='problem_comment'>" + problem_comment_text + "</textarea><input type='hidden' id='problem_id' name='problem_id' value='" + problem_id + "' /><input type='hidden' id='problem_comment_id' value='" + problem_comment_id + "' /><input type='submit' class='button' value='Edit Message' /><input type='button' class='button' id='cancel_comment' data-problem_id='" + problem_id + "' value='Cancel' /></form>";

顺便说一句,它看起来很乱 :) 人们通常如何做这种事情才能使它更干净?

谢谢!

最佳答案

http://jsfiddle.net/G2qsp/1/

据我所知,他们在同一条线上:P

使它更简洁的常规方法(至少,我这样做)是将它放在新的行中,每行末尾带有 +。

又名:

var new_comment_form = 
"<form id='add_comment' method='post'>"+
  "<textarea name='problem_comment' cols=60 rows=6 id='problem_comment'>"+
      problem_comment_text +
  "</textarea>"+
  "<input type='hidden' id='problem_id' name='problem_id' value='" + problem_id + "' />"+
  "<input type='hidden' id='problem_comment_id' value='" + problem_comment_id + "' />"+
  "<input type='submit' class='button' value='Edit Message' />"+
  "<input type='button' class='button' id='cancel_comment' data-problem_id='" + problem_id + "' value='Cancel' />"+
"</form>";

编辑: 如果您仍然遇到一些对齐问题,这就是您想要对 float 进行的大致操作 http://jsfiddle.net/G2qsp/2/

现在,在有人攻击我使用 clear:both 之前逃跑......

关于javascript - 如何将两个按钮放在同一水平线上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8271905/

相关文章:

html - 在下拉菜单上添加过渡

html - 使段落的一部分环绕在 float 图像上方

javascript - 如果已访问后代节点的链接,是否可以从 DOM 中删除元素?

javascript - $http 变量范围问题

javascript - 每次按键时更改单词 javascript/jquery

javascript - window.print() 启动时不包含 CSS 样式

html - IMG 换行(对齐问题)

html - 保持 block 元素水平

javascript - d3.js中这两个代码块有什么区别

javascript - 用户界面路由器 : open modal and pass parent scope parameters to it