簡體   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