简体   繁体   English

如何使用jquery / javascript搜索字符串并在页面加载时替换?

[英]How can I use jquery/javascript to search for a string and replace on page load?

I have a very annoying validation bug from a plugin that is embedding a video. 我有一个非常令人讨厌的验证错误,该错误来自嵌入视频的插件。 I can't change the plugin and need to use it to show the video. 我无法更改插件,需要使用它来显示视频。 Is there a way that I could use js to search for the & and replace it with &amp? 有没有一种方法可以使用js搜索&并将其替换为&amp?

This is the string that it needs to be replaced in: 这是需要替换的字符串:

http://player.vimeo.com/video/72874423?title=0&byline=0&portrait=0;api=1

I tried this, but unfortunately it isn't working: 我试过了,但是不幸的是它没有用:

(function ($, document, undefined) {
$(document).ready(function(){

var str = $( "iframe" ).attr( "src" );
str = str.replace(/&/g,"&");
$( "iframe" ).attr( "src",str );

    });

})(jQuery, document);

That is the only iframe on the page. 那是页面上唯一的iframe。

var str = "http://player.vimeo.com/video/72874423?title=0&byline=0&portrait=0;api=1";
str = str.replace(/&/g,"&amp");
alert(str);

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

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