Jquery 我如何将这些按钮居中

Jquery 我如何将这些按钮居中,jquery,css,Jquery,Css,我的jQuery中有两个函数,它们管理两个按钮,然后显示它们。我希望按钮显示在中间,但是align=center不起作用。有人知道如何在我的jQuery代码中做到这一点吗 jQuery代码如下: function insertQuestion(form) { var $answer = $("<table class='answer'></table>"); $('.allBtns:first-child').each(function() {

我的jQuery中有两个函数,它们管理两个按钮,然后显示它们。我希望按钮显示在中间,但是
align=center
不起作用。有人知道如何在我的jQuery代码中做到这一点吗

jQuery代码如下:

function insertQuestion(form) {   

    var $answer = $("<table class='answer'></table>");

    $('.allBtns:first-child').each(function() {
        var $this = $(this);
        var $allBtnsClass = '';

        $allBtnsClass = $("<input class='allBtns btnsAll' type='button' style='display: inline-block;' value='Select All Answers' onClick='selectAll(this);' />")
            .attr('name', $this.attr('name'))
            .attr('value', $this.val())
            .attr('class', $this.attr('class'));
        }

        $answer.append($allBtnsClass);
    });

    $('.allRemoveBtns:first-child').each(function() {
        var $this = $(this);
        var $removeBtnsClass = '';

        $removeBtnsClass = $("<input class='allRemoveBtns btnsRemove' type='button' style='display: inline-block;' value='Remove All Answers' onClick='removeAll(this);' />")
            .attr('name', $this.attr('name'))
            .attr('value', $this.val())
            .attr('class', $this.attr('class'));
        }

        $answer.append($removeBtnsClass);
    });

    $tr.append($answer);   
}
函数insertQuestion(form){
var$answer=$(“”);
$('.allBtns:first child')。每个(函数(){
var$this=$(this);
var$AllBtnClass='';
$ALLBTNCLASS=$(“”)
.attr('name',$this.attr('name'))
.attr('value',$this.val())
.attr('class',$this.attr('class');
}
$answer.append($allBtnsClass);
});
$('.allRemoveBtns:first child')。每个(函数(){
var$this=$(this);
var$removebtnclass='';
$RemoveBtnClass=$(“”)
.attr('name',$this.attr('name'))
.attr('value',$this.val())
.attr('class',$this.attr('class');
}
$answer.append($removebtnclass);
});
$tr.append($answer);
}

我不知道这是否是您唯一的问题,但您正在将按钮放在
表中
;表格不应直接包含
输入
元素。我想你根本不需要桌子。如果将容器元素设为
div
(例如,使用类
answers
),则可以在样式表中使用此样式:

.answers { text-align: center; }
然后,如果停止在
输入
按钮上设置
显示:内联块
,则默认情况下,它们应显示为内联,然后容器的
文本对齐:居中
应负责将它们居中

您的JavaScript还包含太多的
}
s。它们仅在与
{
s配对时才需要


我希望这能有所帮助。

您的代码中有一些额外的
}
s,我在重新身份时注意到了这些。你确定你的代码正在运行吗?是的,它们在
中未被使用。每个
函数