我遇到了一个问题,无法确定此文本区域值是 iframe 还是简单文本。有人可以帮助我吗?



我正在面临一个问题,以查找此textarea值是iframe还是一个简单的文本。在这里,如果TextArea值等于IFRAME,则我需要将嵌入的IFRAME放入<div class="widgetVideoEdit">中。有人可以帮我吗?

html:

<div class="widgetVideoEdit widgetWrap" style="display: block;"><div class="videoEmbededCode"><textarea class="embededCode" placeholder="Paste here video embeded code"></textarea><button type="button" class="LPbtn-primary LPbtn-lg">insert</button></div><div class="LPtempEditArea"><i class="fa fa-clone LPclone"></i><i class="fa fa-arrows LPdraggable"></i><i class="fa fa-trash LPremove"></i></div><div class="videoPlaceholder"><i class="fa fa-play-circle"></i></div></div>

jQuery:

$(document).on('click', '.LPbtn-primary', function(){
            var embededCode = $(this).parent('.videoEmbededCode').children('.embededCode');
            var alertText = $('<p class="alertText">').text('Please add code').prependTo($(this).parent('.videoEmbededCode'));
            var videoContent = $(embededCode).val();
            //alert(videoContent);
            if($(videoContent) ===''){
                console.log('please add code');
                $(alertText);
                }
                else {
                    $('.widgetVideoEdit').html(videoContent);
                    }
        });

在此处检查:https://jsfiddle.net/issact/0ueefc1p/3/

您可以为<iframe等关键字的Textarea的值添加一些基本检查。

这看起来像:

if (videoContent.indexOf("<iframe") >= 0){
  alert("The text in textarea contains the string <iframe");
} else {
  alert("There does not seem to be an iframe in the textarea text.");
}

javaScript的解决方案可能像这样

$(document).on('click', '.LPbtn-primary', function(){
  var embededCode = $(this).parent('.videoEmbededCode').children('.embededCode');
  var videoContent = $(embededCode).val();
  if($(videoContent) ===''){
    $('<p class="alertText">').text('Please add code').prependTo($(this).parent('.videoEmbededCode'));
  } else {
    $('.widgetVideoEdit').html(videoContent);
  }
});

最新更新