【问题标题】:Replace javascript text with jquery or other in HTML code用 jquery 或 HTML 代码中的其他内容替换 javascript 文本
【发布时间】:2014-01-13 06:46:53
【问题描述】:

我的主页(index.php)看起来像:

<?php start_session();
    ... PHP CODE ...
?>
<html>
   ... HTML CODE ...

<script type="text/javascript">
        var bscTexts =
                {
                    signup: {
                        cropPicture: 'Crop your profile picture',
                    },
                    home: {
                        noFavorites: 'You haven´t added any profiles as favorites'
                    },
                    general: {
                        errorUploading: 'Error uploading, please try again',
                        successfulUploading: 'Votre photo a bien été obtenue',
                        chooseAnotherPicture: 'Choisir une autre photo',
                        loadingMore: 'Loading, please wait...'
                    },
                    notificationBubbles: {
                        /*InterestedInYou */            1: {
                            Text: '[Name] has shown interest in you',
                            Url: "/match/interestedinme"
                        },
                        /*Match */                      2: {
                            Text: 'You and [Name] are now a match',
                            Url: "/match/matches"
                        },
                        /*WinkSent */                   3: {
                            Text: 'You have received a wink from [Name]',
                            Url: "/home/socialstream"
                        },
                        /*LovedPicture */               4: {
                            Text: '[Name] loves one of your pictures',
                            Url: "/home/socialstream"
                        }
                    }
                };
    </script>
... OTHER HTML CODE ...
</html>

我想知道是否可以用jquery或其他(dom)替换文本(字符串语句)

例如:

如果我调用警报(bscTexts.signup.cropPicture);结果是带有“裁剪您的个人资料图片”的弹出警报

我需要知道在页面加载 jquery、javascript 或其他方法后是否可以用法语翻译替换“裁剪您的个人资料图片”以获得此:

<script type="text/javascript">
    var bscTexts =
            {
                signup: {
                    cropPicture: 'Redimensionnez votre photo',
                }
</script>

例如,我需要更改所有字符串。

感谢您的帮助!

【问题讨论】:

    标签: javascript jquery dom text


    【解决方案1】:

    你为什么不先设置法式值而不考虑窗口加载后的变化?

    在 jquery 中有一个函数用于在文档准备好后重写 vars:

    jQuery(function($){
        ... rewrite your vars...
    })
    

    【讨论】:

      【解决方案2】:

      如果您要更改所有字符串,只需再次分配对象:

      bscTexts = { ... };
      

      如果你只有字符串替换每个:

      bscTexts.signup.cropPicture = 'new value';
      .
      .
      bscTexts.notificationBubbles.Text = 'new value';
      

      【讨论】:

      • 我知道,所以当您查看 HTML 源代码时,您总是会看到英文文本...阅读我在上层答案中的评论,我留下了更多信息和详细信息
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-07
      • 2023-03-25
      • 2011-02-02
      • 1970-01-01
      • 2016-02-07
      • 1970-01-01
      • 2014-09-08
      相关资源
      最近更新 更多