Viết một hàm JavaScript để kiểm tra xem một giá trị đã cho có phải là html hay không.
Mã nguồn:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Write a JavaScript function to check whether a given value is html or not.</title>
<script>
function is_html(str)
{
regexp = /<([a-z]+) *[^/]*?>/;
if (regexp.test(str))
{
return true;
}
else
{
return false;
}
}
document.write(is_html(''));
document.write(is_html(''));
document.write(is_html('.selector'));
</script>
</head>
<body>
</body>
</html>
Lưu đồ thuật toán:

Thấy bài viết hữu ích?
Ủng hộ tác giả để có thêm nhiều bài viết chất lượng nhé!