Javascript到HTML替换标签不起作用 [英] Javascript to HTML replace tags not working

查看:67
本文介绍了Javascript到HTML替换标签不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力替换我网站上发布的所有共享代码,但不适合我。

我需要出现在`

I have been working on this to replace every code that is shared on post in my website but is not working for me.
I need everything that appear inside `

<code></code>

`重播所有标签并使用css为其添加颜色。如果有任何简单的方法可以做到这一点,有人可以帮助我吗?我将欣赏jsfiled中的示例代码





以下是代码在我的网站上的显示方式



` to replay all the tags and give it a color using css. please if there is any simple way to do this can someone just help me with that? i will appreciate sample code in jsfiled


And here is how codes display in my website

<pre id="Mpreditor" class="code code-codes language-javascript">
    <code ng-transclude="ng-transclude" class="language-javascript">    
    <span>Hello</span>
    You have to include the `%` signs in the `$params`, not in the query:
    
    $query = "SELECT * FROM tbl WHERE address LIKE ? OR address LIKE ?";
    $params = array("%$var1%", "%$var2%");
    $stmt = $handle->prepare($query);
    $stmt->execute($params);
    </code>
</pre>





我的尝试:



这里是我一直试图使用的代码示例







What I have tried:

here is sample of code that i have been trying to use


function Rep(text){
    text = text.replace(/ /g," ");

    text = text.replace(/<([^\>]+?)>/g, function(match, contents){
        return "<span class="TagColor"><"+contents+"></span>";
    }
    );

    text = text.replace(/\"([^\"]+?)\"/g, function(match, contents){
        return '<span class="StringColor">"'+contents+'"</span>';
      }
    );
    text = text.replace(/\(([^\)]+?)\)/g, function(match, contents){
        return '<span class="OptionsColor">('+contents+')</span>';
      }
    );
    text = text.replace(/\n/g, function(match, contents){
        return '<br />';
    }
    );
    text = text.replace(/\{/g, function(match, contents){
        return '<span class="BracketsColor">{</span>';
    }
    );
    text = text.replace(/\}/g, function(match, contents){
        return '<span class="BracketsColor">}</span>';
    }
    );
    text = text.replace(/\/\*([^\*]+?)\*\//g, function(match, contents){
        return '<span class="CommentColor">/*"+contents+"*/</span>';
    }
    );
      text = text.replace(/\[\](.*?)\[\/\]/g, function(match, contents){
        return '<span class="BBColor">'+contents+'</span>';
    }
    );
    return text;

  }

  //HTML replace
  //==================================================
  $('code').each(function(){
      var text=$(this).html().replace(/       var text=text.replace(/>/g,'>');
      $(this).html(text);
  });

  //google-code-prettify
  //==================================================
  jQuery(window).load(function(){
      prettyPrint();
  });

  //Still on Text format

  var app = angular.module('codelab',[],['$interpolateProvider',
      function($interpolateProvider) {
          $interpolateProvider.startSymbol('[[');
          $interpolateProvider.endSymbol(']]');
          }]);

  app.directive('ngPrism',['$interpolate', function ($interpolate) {
          "use strict";
          return {
            restrict: 'E',
            template: '<pre id="Mpreditor" class="code code-codes language-javascript"><code ng-transclude="ng-transclude" class="language-javascript"> </code></pre>',
            replace:true,
            transclude:true
          };
      }]);

推荐答案

params`,不在查询中:
params`, not in the query:


query =SELECT * FROM tbl WHERE address LIKE?或address LIKE?;
query = "SELECT * FROM tbl WHERE address LIKE ? OR address LIKE ?";


params = array(%
params = array("%


这篇关于Javascript到HTML替换标签不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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