English 中文(简体)
删除部分带有jquery或javascript的Anchor文本
原标题:remove a PART of an Anchor Text with jquery or javascript

页: 1

我的一位法官认为:

<a href="http://something.com">Model 1234 motorbike</a>

I would like to remove the "motorbike" part of the anchor text, to end up with:

<a href="http://something.com">Model 1234</a>

任何人都知道如何这样做?

增 编

<<>strong>update:

链接来自不同的网站。 因此,我可以控制html。 我只想把“机动车”部分从派出的楼房中删除,因此,我网页上没有显示100次。

@Shiv Kumar:是,“机动车”始终是封建案文的最后一部分。 @Phrogz:文字向我的现场发送了现有的模型。 固定案文的最后一部分总是“机动车”,第一部分改动:模式1234,类型4321等。

但我将首先尝试这些法典。

增 编 everyone for the quick replies.

非常感谢。

页: 1

问题回答

a) 修改发给浏览器的超文本,不试图将其寄给客户。 用户 Java倒了什么?

b)

// Get rid of the last word in the text for all anchors referencing
// the domain something.com
$( a[href*="something.com"] ).html(function(oldHTML){
  return oldHTML.replace(/sS+$/,  );
});

// Keep only "Model xxxx"
$( a[href*="something.com"] ).html(function(oldHTML){
  return oldHTML.replace( /^(Model d+).+/,  $1  );
});

<>Edit:从每个环节中具体删除摩托车一词:

$( a ).html(function(oldHTML){
  return oldHTML.replace(   motorbike ,    );
});

添加“Name”类,以过滤链接:

   $(".with_motorbike_txt").each(function() {
        var cur_txt = $(this).html();
        $(this).html(substring(0, cur_txt.indexOf( motorbike ));
    });




相关问题
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.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签