繁体   English   中英

用jquery或其他HTML代码替换JavaScript文本

[英]Replace javascript text with jquery or other in HTML code

我的主页(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)替换文本(字符串语句)

例如 :

如果我打电话给alert(bscTexts.signup.cropPicture); 结果是带有“裁剪您的个人资料照片”的弹出警报

我需要知道在页面加载了jquery,javascript或其他内容之后是否有可能用法语翻译替换“ Crop your profile picture”来获得此信息:

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

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

谢谢您的帮助!

为什么不先设置法式值,而不管窗口加载后的更改如何?

在jquery中有一个函数可以在文档准备好后重写var:

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

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

bscTexts = { ... };

如果您只有字符串,请替换每个字符串:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM