JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<div id="postText">
тестовая строчка простая<br>
тестовая строчка простая<br>
тестовая строчка простая<br>
тестовая строчка простая<br>
</div>
<input type="checkbox" class='oneCheckbox' id="date" >
<input style="width: 430px; float: left; margin-top: 5px;" type="text" class="form-control" name = "nameInformation[]" id="prizName" placeholder="Приз">
<div class="information_json_plus">
<div>
<span style="float: right" class="btn btn-success plus pull-right">+</span>
</div>
</div>
</body>
CSS
.information_json * {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.pull-right {float: left;}
.form-control {
display: block;
width: 100%;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
-webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
-o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
}
.btn {
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
font-weight: 400;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
}
.btn-danger {
color: #fff;
background-color: #d9534f;
border-color: #d43f3a;
}
.btn-success {
color: #fff;
background-color: #5cb85c;
border-color: #4cae4c;
}
JavaScript
/// выбор одно чекбокса из группы
$('body').on('click',".oneCheckbox", function(){
if (this.checked) {
$('.oneCheckbox').attr('checked',false);
this.checked=true;
};
});
// формируем новые поля
jQuery('.plus').click(function(){
jQuery('.information_json_plus').before(
'<div><input type="checkbox" class="oneCheckbox" id="date" >' +
'<input style="width: 430px; float: left; margin-top: 5px;" type="text" class="form-control" name = "nameInformation[]" id="prizName" placeholder="Приз">' +
'<span class="btn btn-danger minus pull-right" style="float: right; margin-top: 5px;">–</span></div>'
);
});
// on - так как элемент динамически создан и обычный обработчик с ним не работает
jQuery(document).on('click', '.minus', function(){
jQuery( this ).closest( 'div' ).remove(); // удаление строки с полями
});
// функция копирования выделенного участка текста
function getSelectedText(){
var text = "";
if (window.getSelection) {
text = window.getSelection();
}else if (document.getSelection) {
text = document.getSelection();
}else if (document.selection) {
text = document.selection.createRange().text;
}
return text;
}
$('#postText').on('mouseup', function(e){
if ($('#date').is(':checked')) {
$("#prizName").val(getSelectedText());
}
});