English 中文(简体)
频率取代从编号开始的所有座标,并增加链接
原标题:Jquery replace all strings starting with # and add link

我在电文板上有一大块或案文,其中将载有从编号开始的示意图。 我能否用 j子来取代这些 the子?

例如,变化:

<div id="mydiv">This is my #block of text with #multiple hash strings</div>

:

<div id="mydiv">This is my <a href="newpage.asp?block">#block</a> of text with <a href="newpage.asp?multiple">#multiple</a> hash strings</div>

提前感谢!

最佳回答

您可使用以下代码取代插图:

var string = "#has etc #has ";
string = string.replace(/#(S+)/g,  <a href="newpage.asp?$1">#$1</a> );
问题回答

这项工作将:

$( *:contains("#") ).each(function(){
 if($(this).children().length < 1) 
      $(this).html( 
           $(this).text().replace(
                /#(.*)#/
                , <a href=newpage.asp? +$(this).text()+ > +$(this).text()+ </a> 
           )  
       ) 
});




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签