Я установил текстовые поля, созданные динамически, которые я хотел бы показывать рядом, а не показывать одно под другим.
<div class = "wrap-login100 p-l-20 p-t-25">
<form class = "form" name = "add_name" id = "add_name">
<div class = "control-group">
<div class = "inc">
<div class = "testing">
<div class = "form-group col-md-10">
<input type = "text" class = "form-control" id = "fname" name = "fname" placeholder = "Enter Manger First Name" >
<div id = "error" style = "display:none; color: red;">Enter First Name before submission!</div>
</div>
<div class = "form-group col-md-10">
<input type = "text" class = "form-control" id = "lname" name = "lname" placeholder = "Enter Manager Last Name" >
<div id = "error2" style = "display:none; color: red;">Enter Last Name before submission!</div>
</div>
<div class = "form-group col-md-10">
<button class = "btn btn-primary" type = "submit" id = "append" name = "append">
Add Team Details</button>
</div>
<br>
<br>
</div>
</div>
<div class = "col-md-10 text-center">
<input type = "button" class = "btn btn-info btn-lg" id = "submit" name = "submit" value = "Register"/>
</div>
</div>
</form>
</div>
Это прекрасно, но когда я динамически создаю текстовое поле, я хочу, чтобы оно располагалось рядом. вместо этого:
Вот код динамического текстового поля:
<script>
var counter=0;
jQuery(document).ready( function ()
{
$("#append").click( function(e)
{
counter++;
e.preventDefault();
$(".inc").append('<div class = "testing">\
<div class = "form-group col-md-10">TE - ' +counter+ '</div>\
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "tename[]" id = "tename" placeholder = "Enter TE Name"> </div>\
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "hq[]" id = "hq" placeholder = "Enter HQ"></div> \
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "state[]" id = "state" placeholder = "Enter State"> </div>\
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "department[]" id = "department" placeholder = "Department"> </div>\
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "teamno[]" id = "teamno" placeholder = "Enter team number"> </div>\
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "leadname[]" id = "leadname" placeholder = "Enter Lead Name"></div>\
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "holiday[]" id = "holiday" placeholder = "Numbers of holidays entire week"></div>\
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "offpermonth[]" id = "offpermonth" placeholder = "Off Per month"></div>\
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "lop[]" id = "lop" placeholder = "LOP Details"></div>\
<a href = "#" class = "remove_this btn btn-danger btn-lg">Remove</a>\
<br>\
<br>\
</div>');
return false;
});
jQuery(document).on('click', '.remove_this', function() {
jQuery(this).parent().remove();
counter--;
return false;
});
$('#submit').click(function()
{
var textBox = $("#amname").val();
var textBox2 = $("#rmname").val();
if (textBox == "")
{
$("#error").show('slow');
}
else if (textBox2 == "")
{
$("#error2").show('slow');
}
else
{
$.ajax({
url:"savedata.php",
method:"POST",
data:$('#add_name').serialize(),
success:function(data)
{
alert(data);
//window.location.replace("lobby.php");
}
});
}
})
});
Как мне это сделать?






display: inline-block твой друг. Добавьте новый класс или добавьте form-group css, как показано ниже.
var counter = 1;
$(".inc").append('<div class = "testing">\
<div class = "form-group col-md-10">TE - ' + counter + '</div>\
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "tename[]" id = "tename" placeholder = "Enter TE Name"> </div>\
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "hq[]" id = "hq" placeholder = "Enter HQ"></div> \
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "state[]" id = "state" placeholder = "Enter State"> </div>\
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "department[]" id = "department" placeholder = "Department"> </div>\
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "teamno[]" id = "teamno" placeholder = "Enter team number"> </div>\
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "leadname[]" id = "leadname" placeholder = "Enter Lead Name"></div>\
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "holiday[]" id = "holiday" placeholder = "Numbers of holidays entire week"></div>\
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "offpermonth[]" id = "offpermonth" placeholder = "Off Per month"></div>\
<div class = "form-group col-md-10"> <input class = "form-control" type = "text" name = "lop[]" id = "lop" placeholder = "LOP Details"></div>\
<a href = "#" class = "remove_this btn btn-danger btn-lg">Remove</a>\
<br>\
<br>\
</div>');div.form-group {
display: inline-block
}<script src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class = "inc"></div><style> div.form-group { display: inline-block } </style> Я попробовал это, но не сработало. Я что-то пропустил?
Попробуйте с важным, похоже на переопределение css. div.form-group { display: inline-block !important; }
все еще такой же :(
Или дайте новый класс с помощью css.
Прочтите это один раз
Есть 3 способа, я попробовал упомянутый метод таблицы, и это сработало для меня.
Способ разместить три div рядом с помощью свойства display.
дисплей: таблица; Это свойство используется для элементов (div), которые ведут себя как таблица.
дисплей: таблица-ячейка; Это свойство используется для элементов (div), которые ведут себя как td.
display:table-row Это свойство используется для элементов (div), которые ведут себя как tr.
<!DOCTYPE html>
<html>
<head>
<!-- CSS style to place three div side by side -->
<style>
.container .box {
width:540px;
margin:50px;
display:table;
}
.container .box .box-row {
display:table-row;
}
.container .box .box-cell {
display:table-cell;
width:33%;
padding:10px;
}
.container .box .box-cell.box1 {
background:green;
color:white;
text-align:justify;
}
.container .box .box-cell.box2 {
background:lightgreen;
text-align:justify
}
.container .box .box-cell.box3 {
background:lime;
text-align:justify;
}
</style>
</head>
<body>
<center>
<h1 style = "color:green;">GeeksforGeeks</h1>
<div class = "container">
<div class = "box">
<div class = "box-row">
<div class = "box-cell box1">
It is a good platform to learn programming.
It is an educational website. Prepare for
the Recruitment drive of product based
companies like Microsoft, Amazon, Adobe etc
with a free online placement preparation
course.
</div>
<div class = "box-cell box2">
The course focuses on various MCQ's &
Coding question likely to be asked in
the interviews & make your upcoming
placement season efficient and successful.
</div>
<div class = "box-cell box3">
Any geeks can help other geeks by writing
articles on the GeeksforGeeks, publishing
articles follow few steps that are Articles
that need little modification/improvement
from reviewers are published first.
</div>
</div>
</div>
</div>
</center>
</body>
</html>
Похоже, что каждое из текстовых полей заключено в
col-md-10, что означает, что они будут занимать 10 столбцов из 12 и помещать следующий элемент в новую строку. Другая вещь — это использование классаform-control, он сделает доступным управление для использования полной ширины. Одна вещь, которую вы можете сделать, это изменить дизайн вашей формы и использоватьcol-md-6, чтобы вы могли иметь 2 рядом или изменить стиль столбца в соответствии с необходимостью. Возможно, вам придется использовать div-оболочку какrow. Наверное, датьrowклассdiv.testing