Jquery 我如何将这些按钮居中
我的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() {
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,我在重新身份时注意到了这些。你确定你的代码正在运行吗?是的,它们在中未被使用。每个函数