【问题标题】:How to highlight a certain range of text inside textarea with jQuery如何使用 jQuery 在 textarea 中突出显示特定范围的文本
【发布时间】:2014-08-24 12:01:18
【问题描述】:

是否可以使用 jQuery 在文本区域内突出显示特定范围的字符。我已经看过并尝试了一些事情无济于事。我试图突出显示文本区域内 iframe 代码的开始到结束。

if ($('#textarea').val().match(/<iframe(.*?)<\/iframe>/)) {
    // code here
}

谢谢

【问题讨论】:

    标签: javascript jquery iframe highlight


    【解决方案1】:

    您可以在工作中使用:contains()。例如。

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>contains demo</title>
      <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    </head>
    <body>
    
    <div>John Resig</div>
    <div>George Martin</div>
    <div>Malcom John Sinclair</div>
    <div>J. Ohn</div>
    
    <script>
    $( "div:contains('John')" ).css( "text-decoration", "bold" );
    </script>
    
    </body>
    </html> 
    

    会导致

    约翰·雷西格

    乔治·马丁

    马尔科姆·约翰·辛克莱

    J。呵呵

    请参阅documentation here。示例来自 api.jquery.com

    【讨论】:

    • 这不会突出显示我想要的代码。
    猜你喜欢
    • 1970-01-01
    • 2011-06-29
    • 1970-01-01
    • 2011-01-24
    • 2011-09-08
    • 1970-01-01
    • 1970-01-01
    • 2020-08-26
    • 1970-01-01
    相关资源
    最近更新 更多