dom如何使用hasAttributes判断具有任何属性

2024-12-01 10:03:51

1、创建一个名称为hasAttributes 的html文件 ,并在body中加入一个onclick属性

dom如何使用hasAttributes判断具有任何属性

2、添加一个button按钮,在点击事件中加入自定义函数myhasAttributes

dom如何使用hasAttributes判断具有任何属性

3、添加一p标签,设置id 为 showhattributes

dom如何使用hasAttributes判断具有任何属性

4、创建一个自定义函数 myhasAttributes

dom如何使用hasAttributes判断具有任何属性

5、在自定义函数中获取对象,在用hasAttributes方法来判断该body对象中是否拥任何属性,将结果显示到p标签中

dom如何使用hasAttributes判断具有任何属性

6、在浏览器中打开文件,点击button查看效果

dom如何使用hasAttributes判断具有任何属性
猜你喜欢