rak*_*los 6 javascript validation jquery
如何执行jquery验证以检查textarea是否不包含html标签?(如果错误的话)
(顺便说一句,我阻止html在服务器上通过)
xn.*_*xn. 11
您可以使用John Resig的HTML解析器(http://bit.ly/hsMq4x),也可以使用更简单的解决方案来查找开始标记.
$('textarea').each(function() {
if ($(this).val().match(/<(\w+)((?:\s+\w+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/)) {
alert('html found');
}
});
Run Code Online (Sandbox Code Playgroud)
Neal的解决方案遭受包含有效jquery选择器的textareas的误报,例如仅包含"a"的textarea.
Nea*_*eal 10
尝试这个尺寸:
$('textarea').each(function(){
var text = $(this).text();
if($(text).length > 0){
console.log('contains html elements')
}
else {
console.log('no html elements')
}
});
Run Code Online (Sandbox Code Playgroud)
小提琴就在这里
| 归档时间: |
|
| 查看次数: |
8925 次 |
| 最近记录: |