替换WordPress插件中的硬编码JavaScript字符串

时间:2019-04-14 05:36:01

标签: javascript wordpress

我想在不更改插件源代码的情况下替换字符串“ Submitting”(请参见下文)。

我打算用新脚本替换它。您的代码方法是什么?

感谢您的帮助!

$( ".aol_app_form" ).submit(function(){
        var datastring = new FormData(document.getElementById("aol_app_form"));
        $.ajax({
                url: aol_public.ajaxurl,
                type: 'POST',
                dataType: 'json',
                data: datastring,
                //async: false,
                cache: false,
                contentType: false,
                processData: false,
                beforeSend: function(){
                    $('#aol_form_status').removeClass();
                    $('#aol_form_status').html('Submitting . . . . . ');
                    $('#aol_form_status').addClass('alert alert-warning');
                    $(".aol-form-button").prop('disabled', true);
                },

1 个答案:

答案 0 :(得分:1)

您可以使用DOMSubtreeModified检查div #aol_form_status的内容更改

$('#aol_form_status').bind("DOMSubtreeModified",function(){
  var content = $(this).html();
  if( content == 'Submitting . . . . . '){
    $(this).html('Your html content want to change here');
  }
});

演示:

$('#aol_form_status').bind("DOMSubtreeModified",function(){
  var content = $(this).html();
  if( content == 'Submitting . . . . . '){
    $(this).html('Your html content want to change here');
  }
});

$('#aol_form_status').html('Submitting . . . . . ');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="aol_form_status"></div>