English 中文(简体)
在一个超文本部分内使用舱位对另一个部分的更正/拷贝
原标题:Send/copy text within one HTML element to another using jquery
  • 时间:2012-01-11 11:42:18
  •  标签:
  • jquery
  • html

我一直在寻找一种 j的功能,使我只读到某一要素中的“范围与过去”,即:<代码><li>或<div>,并将其列入另一个内容。 这样做不应破坏案文正从中抄录的内容。

I have a jsfiddle document which demonstrates my best attempt and a more practical description: http://jsfiddle.net/HDBLd/

Thanks very much.

P.S 我要澄清的是,我不想把该要素中的案文抄送给使用者,然后抄送其他内容。

最佳回答

将一个部分的超文本发送到另一个部分,你可以简单地利用原始要素的产出html()作为目标的来源,例如:

jQuery($ => {
  $( li ).on( click , function() {
    $( #lorem ).html($(this).html());
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<div id="lorem">
  This is the text that should change
</div>

<div id="impsum">
  <ul>
    <li>This is the text that will replace the other piece of text. I need to find a function that will just copy the text in here - not the whole li with the bullet as well.</li>
  </ul>
</div>

请注意,如果你想要忽略原要素内的任何超文本,你也可以使用<代码>text()而不是html()。

问题回答
$("#lorem").html($(this).html());

http://api.jquery.com/text“rel=“nofollow”>text()。

$("#lorem").text($(this).text());




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签