Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery从url中删除特定区域_Javascript_Jquery_Html - Fatal编程技术网

Javascript 使用jquery从url中删除特定区域

Javascript 使用jquery从url中删除特定区域,javascript,jquery,html,Javascript,Jquery,Html,我有一个URL,比如http://myurleg.com/ar/Message.html单击后,我想将其中的ar替换为en 这意味着如果我的url是:http://myurleg.com/ar/Message.html 点击后应变成:http://myurleg.com/en/Message.html 我刚试过 <script> $(document).ready(function () { $('#lng_flip').click(function ()

我有一个URL,比如
http://myurleg.com/ar/Message.html
单击后,我想将其中的
ar
替换为
en

这意味着如果我的url是:
http://myurleg.com/ar/Message.html

点击后应变成:
http://myurleg.com/en/Message.html

我刚试过

<script>
    $(document).ready(function () {

        $('#lng_flip').click(function () {

            var url = window.location.href.split('/')[0];
        });
    });
</script>

$(文档).ready(函数(){
$('#lng_flip')。单击(函数(){
var url=window.location.href.split('/')[0];
});
});

有人能帮忙吗?

en
替换数组中的
ar
,然后使用再次加入它

var url='1〕http://myurleg.com/ar/Message.html.split('/');
网址[3]=“en”;
url=url.join('/');

document.write(url)
en
替换数组中的
ar
,然后使用再次加入它

var url='1〕http://myurleg.com/ar/Message.html.split('/');
网址[3]=“en”;
url=url.join('/');

document.write(url)您可以使用字符串
替换

var str=”http://myurleg.com/ar/Message.html";
文件编写(str);
var res=str.replace(“/ar/”,“/fr/”);

编写(“
结果:”+res)您可以使用字符串
替换

var str=”http://myurleg.com/ar/Message.html";
文件编写(str);
var res=str.replace(“/ar/”,“/fr/”);

编写(“
结果:”+res)支持路径开头任意两个字母的语言代码的通用解决方案是:

location.href = location.href.replace(/(\/\/.*?\/)\w{2}(.*)/, '$1en$2');
虽然有时只操作
位置.路径名
更有意义:

location.pathname = location.pathname.replace(/\/\w{2}(.*)/, '/en$1');

在路径开头支持任何两个字母的语言代码的通用解决方案是:

location.href = location.href.replace(/(\/\/.*?\/)\w{2}(.*)/, '$1en$2');
虽然有时只操作
位置.路径名
更有意义:

location.pathname = location.pathname.replace(/\/\w{2}(.*)/, '/en$1');
试试这个

var str = 'http://myurleg.com/ar/Message.html'; 
var txt = str.replace(/ar/i,"en");
还是你的情况

var url = window.location.href;
window.location.href = url.replace(/ar/i,"en");
试试这个

var str = 'http://myurleg.com/ar/Message.html'; 
var txt = str.replace(/ar/i,"en");
还是你的情况

var url = window.location.href;
window.location.href = url.replace(/ar/i,"en");