Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use setAttribute in js

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "how to use setAttribute in js", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to use setAttribute in js" this article.

SetAttribute this method, in the JSP built-in objects session and request have this method, the purpose of this method is to save data, and then you can also use the getAttribute method to extract. For example, now there is another User object, Usercurruser=newUser ("zhangsan", 20, "male").

The specific usage of setAttribute

1 curruser request. SetAttribute ("curruser", curruser) this method is to save the curruser object in the request scope, and then you can get your value in the page you forward into, and if you know some frames, those frame tags can also be obtained, such as struts tags and jstl. If you don't know how to do this, you can write a java script on the jsp page to get:, display the value: on the jsp page.

2 curruser session. SetAttribute ("session", curruser). The only difference between this method and the above is the scope, that is, when you start the whole program, if you save the data in session, then no matter which page you are on, you can get this value at any time, globally, as long as your program is started. The default expiration time of session is 30 minutes, which is not valid. You can modify this value.

Detailed explanation of the usage of setAttribute in js

Element.setAttribute (attributename,attributevalue)

The setAttribute () method adds the specified attribute and assigns the specified value to it. See the example of W3C

Document.getElementsByTagName ("INPUT") [0] .setAttribute ("type", "button")

We often need to dynamically add various attributes to Element in JavaScript, which can be achieved by using setAttribute (), which involves browser compatibility.

Varbar=document.getElementById ("foo")

Bar.setAttribute ("onclick", "_ javascript:alert ('Thisisatestworthy');")

Here we use setAttribute to specify the onclick attribute of e, which is simple and easy to understand. But IE does not support it. It is not that IE does not support setAttribute.

Instead, it does not support setting some properties with setAttribute, such as object properties, collection properties, and event properties, that is, setting style and onclick properties with setAttribute.

It doesn't work in IE. In order to achieve the effect of being compatible with various browsers, the object properties, collection properties and event properties of Element can be set by dot notation.

The above is all the contents of the article "how to use setAttribute in js". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report