我有一个输入和一个模态,我想将文本从输入追加到模态
$("#myBtn").click(function() {
//$('#title-for-modal').clone().appendTo('#title-to-modal');
console.log($("#title-for-modal").contents().appendTo('#title-to-modal').end());
//$('#title-for-modal').append('#title-to-modal'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="item-details">
<div class="row padding-tab-row">
<span class="text-design col-xs-6 text-left">Add Keywords</span>
<input id="title-for-modal" class="col-xs-6 transparent-input" type="text" name="keywords">
</div>
</span>
<div id="next-button2" class="text-center">
<button id="myBtn" name="next_button2" class="next-button-tab-2">Next</button>
</div>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header text-center">
<span class="close "></span>
<p id="title-to-modal" class="modal-title"></p>
</div>
<div class="modal-body">
<p>Some text in the Modal Body</p>
<p>Some other text...</p>
</div>
</div>
</div>
这就是我尝试过的,但如果有人可以帮助我那就行不通。谢谢
答案 0 :(得分:1)
您必须使用value
方法从输入中获取.val()
并将其设置为p
元素。
你需要使用它:
$('#title-to-modal').text($('#title-for-modal').val());
答案 1 :(得分:1)
您需要使用.val()
获取元素的值,.text()
来获取/设置p
元素的文本:
$('#title-to-modal').text($('#title-for-modal').val());
答案 2 :(得分:0)
试试这个......
<script type="text/javascript">
var title=$('#title-for-modal').val();
$('#title-to-modal').text(title);
</script>