本篇文章主要给大家介绍jquery中hasclass()用法介绍,希望对需要的朋友有所帮助!

hasclass什么意思?
hasClass()是jQuery中的一个内置方法,用于检查具有指定类名的元素是否存在。
语法:
$(selector).hasClass(className);
参数:它接受一个“className”参数,该参数指定需要在所选元素中搜索的类名。
返回值:如果搜索成功,返回true,否则返回false。
jQuery hasClass()方法的使用示例:
<meta>
<script>
</script>
<script>
$(document).ready(function() {
$("button").click(function() {
alert($("p").hasClass("find"));
});
});
</script>
<style>
.find {
font-size: 120%;
color: green;
}
body {
width: 50%;
height: 200px;
border: 2px solid green;
padding: 20px;
}
</style><h1>标题1</h1>
<p>PHP中文网!</p>
<p>这是普通段落</p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/gongju/2331" title="jQuery 1.12.4"><img
src="https://img.php.cn/upload/manual/001/431/639/6a21619eac924328.png" alt="jQuery 1.12.4" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/gongju/2331" title="jQuery 1.12.4" class="overflowclass">jQuery 1.12.4</a>
<p class="overflowclass">jQuery 1.12.4是jQuery 1.x系列的最后一个正式稳定版本,由jQuery团队于2016年发布。该版本主要面向需要兼容旧版浏览器环境的网站和Web应用,尤其适用于仍需支持Internet Explorer 6、Internet Explorer 7、Internet Explorer 8等老旧浏览器的项目。</p>
</div>
<a rel="nofollow" href="/xiazai/gongju/2331" title="jQuery 1.12.4" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div>
<button>点击我!</button>
输出:

当点击“点击我”按钮时,出现如下弹窗

相关推荐:《jQuery教程》
本篇文章就是关于jQuery中hasClass()的意思及用法详解,简单易懂,希望对需要的朋友有所帮助!










