這只是一個簡單的編輯。我想改變標題,所以如果我要點擊「編輯」圖標,那麼標題將變爲文本框,「編輯」圖標將變爲「保存」圖標。將文本標籤替換爲不與replaceWith()工作的輸入字段
$('#editheader').click(function(e){
var category = $(this).closest("h3").text();
$(this).replaceWith("<a href=''> <i class='fa fa-save' aria-hidden='true' style='color:green'></i> </a>" );
$(this).closest("h3").replaceWith("<input value='" + category + "' >");
e.preventDefault();
});
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h3 class="panel-title"> Letters To Investors
<a href="#" id="editheader">
<i class="fa fa-pencil" aria-hidden="true" style="color:green"></i>
</a>
</h3>
<h3 class="panel-title"> Tax Documents
<a href="#" id="editheader">
<i class="fa fa-pencil" aria-hidden="true" style="color:green"></i>
</a>
</h3>
我想這樣的作品。 $(this).hide(); $(this).closest(「h3」)。hide(); $('#editForm')。show(); –