简体   繁体   English

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

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

I'm facing an issue to find if this textarea value is iframe or a simple text. 我在查找此textarea值是iframe还是简单文本时遇到问题。 Here if the textarea value is equal to iframe then i need put the embeded iframe into <div class="widgetVideoEdit"> . 如果textarea值等于iframe,则需要将嵌入的iframe放入<div class="widgetVideoEdit"> Can someone help me? 有人能帮我吗?

HTML: 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: 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);

                    }

        });

Check it here: https://jsfiddle.net/Issact/0ueefc1p/3/ 在这里检查: https : //jsfiddle.net/Issact/0ueefc1p/3/

You could add some basic check for the value of the textarea for keywords like <iframe etc. 您可以为<iframe等关键字添加一些基本检查,以检查textarea的值。

This would look like so: 看起来像这样:

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.");
}

The solution of your javascript could be like this 您的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