使用jquery删除所有的href链接 [英] Remove all href links using jquery

查看:264
本文介绍了使用jquery删除所有的href链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从已解析的网站中删除所有链接,然后删除了一个div并放置在主代码中。问题是,我试图删除提取的div中的所有'href'链接,但无法获取任何地方。我曾尝试使用CSS,但只能在Chrome中使用,而且必须使用IE。我已经看过'php simple html dom'解析器,看看我能否在文件保存之前做到这一点,但不能得到任何工作。所以我最后的手段是使用'jquery',但问题是要删除的链接正在从文件中提取,而不是直接在代码中。如果有人可以帮助我,我会很感激。以下是我使用的代码。

I am trying to remove all the links from a parsed site which has then had a div removed and placed in the main code. The problem is that I am trying to remove all the 'href' links in the extracted div but am unable to get anywhere. I have tried using 'CSS' and works but only in chrome and I have to use IE. I have looked at 'php simple html dom' parser to see if i could do it before the file is saved but can't get anything to work. so my last resort is to use 'jquery' but the problem is that the links to remove is being extracted from the file and is not directly in the code. If anyone could help me I would really appreciate it. below is the code I am using.

<head>
   <meta http-equiv="content-type" content="text/html;charset=UTF-8">
   <meta http-equiv="content-language" content="en">
   <meta name="viewport" content="width=500" />
   <title>example News</title>
   <link rel="stylesheet" type="text/css" href="site/wwwRand1.css">
   <?php 
      include( 'site/simple_html_dom.php'); 
      $html=file_get_html( 'http://example.com/home.php'); 
      $html->save('site/result.htm')                      
      ?>
   <script type="text/javascript" src="site/jquery.js"></script>
   <script type="text/javascript">
      $('document').ready(function() {
      $('#postsArea').load('site/result.htm #postsArea');
      });
   </script>
</head>
<body>
   <div id="wrap">
      <div id="postsArea"></div>
   </div>
</body>


推荐答案

只要从< a /> tags

Just remove the href attribute from the <a /> tags

$("#postsArea").load( "site/result.htm", function() {
   $("#postsArea a").removeAttr("href")
});

如果您仍然希望标签显示为可点击...

If you still want the tags to appear clickable...

$("#postsArea a").removeAttr("href").css("cursor","pointer");

希望这可以帮助您

这篇关于使用jquery删除所有的href链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆