您可以使用hasAttribute方法:
// Attach the event to the button
$('button').on('click', function() {
// This will refer the element from where event has originated
if (this.hasAttribute("style")) {
alert('yes')
} else {
alert('no')
}
})
Run Code Online (Sandbox Code Playgroud)
如果要使用jQuery库,可以直接使用条件attr中的方法if。
if($('#yourElement').attr('someProp')){}
Run Code Online (Sandbox Code Playgroud)
或者,您也可以使用 jQuery is选择器:
if ($(this).is('[style]')) {// rest of the code}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19582 次 |
| 最近记录: |