繁体   English   中英

我在查找此textarea值是iframe还是简单文本时遇到问题。 有人能帮我吗?

[英]I'm facing an issue to find if this textarea value is iframe or simple text. Can someone help me?

我在查找此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);
  }
});

暂无
暂无

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

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