简体   繁体   English

如何将jquery中的值打印为html文本?

[英]How to print the values in jquery into html text?

I wanted to join the HTML text with the values of the item.certificate_name . 我想将HTML文本与item.certificate_name的值结合item.certificate_name I've tried many things but any of it didn't works. 我已经尝试了很多东西,但是都没有用。

The line I mean is I commented <!-- I WANTED THE CERTIFICATE NAME TO BE HERE--> . 我要说的是我评论的行<!-- I WANTED THE CERTIFICATE NAME TO BE HERE--> I've already inspected, I've already got the name value. 我已经检查过了,已经有了名称值。 The only problem is how to join the text with the value? 唯一的问题是如何将文本与值连接起来?

<div class="col-xs-12">
  <div class="row">
    <div class="col-xs-2">
      <i class="glyphicon glyphicon-trash center" style="font-size: 50px"></i>
    </div>
    <div class="col-xs-8">
      <div class="clTulisanHapus center" id="idTulisanHapus">
        Anda Yakin ingin menghapus Pelatihan?
        <!-- I WANTED THE CERTIFICATE NAME TO BE HERE -->
      </div>
    </div>
  </div>
</div>
<div class="col-md-offset-8">
  <div class="btn-group">
    <input type="hidden" id="idDataId">
    <input type="hidden" id="idDataNama">
    <button type="button" id="idBtnHapusBatal" class="btn clBtnMdlHapus">Tidak</button>
    <button type="button" id="idBtnHapusHapus" data-id="${item.id}" class="btn clBtnMdlHapus">Ya</button>
  </div>
</div>
$('#idBtnHapusHapus').click(function() {
  var angka = $('#idDataId').val();
  var angka = $('#idDataNama').val();
  debugger;

  $.ajax({
    url: './hapussertifikasi/' + angka,
    type: 'DELETE',
    success: function(model) {
      debugger;
      window.location = './sertifikasi'
    },
    error: function(model) {
      debugger;
    }
  });
});

Use Node.textContent to concatenate the text content of the div with item.certificate_name value and CSS white-space: pre; 使用Node.textContentdiv的文本内容与item.certificate_name值和CSS white-space: pre; to wrap text on line breaks: 在换行符上换行:

 var item = { certificate_name: 'Certificate Name' }; var div = document.getElementById('idTulisanHapus'); div.style.whiteSpace = "pre"; div.textContent += ' ' + item.certificate_name 
 <div class="clTulisanHapus center" id="idTulisanHapus"> Anda Yakin ingin menghapus Pelatihan? </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM