简体   繁体   English

如何使用jQuery选择文本区域内的所有URL?

[英]How to select all URLs inside a text area using jQuery?

I can select all img link as well as PDF link using the following: 我可以使用以下选项选择所有img链接以及PDF链接:

    $("a[href$='pdf']").append('<img src="pdf.jpg" style="width:20px;height:20px;" > ');
    $("a[href$='jpg']").append('<img src="jpg.jpg" style="width:20px;height:20px;" > ');

Now I have a text area 现在我有一个文本区域

 <textarea id="mytxt" name='post' style='width:100%;height:400px;margin-top:10px;border:solid thin #F1F1F1;line-height:20px;'>

  </textarea>


 $("#mytxt:contains('.jpg')").append('<img src="jpg.jpg" style="width:20px;height:20px;" > ');

The above selector won't work. 上面的选择器不起作用。

you cannot append a DOM element inside a textarea, so the above code can't work 你不能在textarea中附加一个DOM元素,所以上面的代码不能工作

the selector itself $("#mytxt:contains('.jpg')") is perfectly working when a .jpg occurence is found : see fiddle http://jsfiddle.net/Mqu66/ 当发现.jpg时,选择器本身$("#mytxt:contains('.jpg')")完全正常工作:请参阅小提琴http://jsfiddle.net/Mqu66/

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

相关问题 jQuery从文本区域选择所有电子邮件 - jQuery select all emails from text area 如何使用 jquery 重置所有输入、li 和文本区域字段 - How to reset all input, li and text area fields using jquery 使用jQuery根据其中的文本设置文本区域的高度 - Setting height of text area based on text inside of it using jQuery 如何使用类名称通过Jquery在文本区域内获取文本内容 - How to get the text content inside a Text Area with Jquery using its class name 如何使用Jquery从中继器内的文本框中选择文本? - How to select the text from my textbox inside a repeater using Jquery? 如何使用fabricjs计算canvas边界内所有文本对象的面积? - How do I calculate area of all text objects inside the canvas bounds using fabricjs? 如何添加 <select>或CTKEditor文本区域内的组合框 - How to add a <select> or combobox inside CTKEditor text area 如何选择包含的所有文本 <pre> 使用jQuery? - How do I select all text contained in <pre> using jQuery? 如何使用JavaScript / jQuery选择(突出显示)表中的所有文本? - How to select (highlight) all text in table using JavaScript/jQuery? 如何从单个表单元素中的多个字段集中获取输入字段(包括选择,文本区域)的所有值? - How do I get all the value of Input fields (including select, text-area) from multiple fieldsets inside a single form element?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM