替换整个文档JQuery中的字符 [英] replacing characters in entire document JQuery

查看:82
本文介绍了替换整个文档JQuery中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了许多不同的方法来解决这个问题,但是没有任何效果.现在我有:

    $(document).ready(function () {
    $(".page").click(function () {

        var html = $(document).html();

        html.replace("[", "<");

        alert("here");
    });


 });

这拒绝工作.它也将不允许我做任何事情,例如Jquery实例如何进行

  $("[").replaceWith("<");

在我看来,.replace甚至不在jQuery中,即使很多示例似乎都将它作为查询的一部分.有什么建议?这开始让我感到沮丧.我尝试传递一个特定的div,但它仍然无法正常工作.有任何想法吗?任何帮助将不胜感激!

解决方案

这是您想要的吗?

$(document.documentElement).html(function(i,val){
    return val.replace(/\[/g,'<');
});

文档 本身不是DOM Element,您应该改为使用 document.documentElement .. >

I have tried a number of different approaches to this but nothing is working. Right now I have:

    $(document).ready(function () {
    $(".page").click(function () {

        var html = $(document).html();

        html.replace("[", "<");

        alert("here");
    });


 });

This refuses to work. It will also not allow me to do anything how the Jquery exmaples go for instance

  $("[").replaceWith("<");

It seems to me that .replace is not even in jQuery even though a lot of examples seem to have it as part of query. Any suggestions? This is starting to frustrate me. I have tried passing in a particular div and it still refuses to work. Any ideas? Any help would be greatly appreciated!

解决方案

Is this what you want?

$(document.documentElement).html(function(i,val){
    return val.replace(/\[/g,'<');
});

document itself is not a DOM Element,you should use document.documentElement instead.

这篇关于替换整个文档JQuery中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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