copyoc property copy和setoc property copy有什么区别

Cookies improve the way our website works, by using this website you are agreeing to our use of cookies. For more information see our privacy policy.
log in / join
You are here:
& setProperty
Browser support:
Adds a property with the specified name and value to the current style object.
Note: The setProperty method is supported in Internet Explorer from version 9.
If a property with the same name exists on the current style object, then it modifies its value.
In older Internet Explorer versions (and in newer ones as well), the
method provides similar functionality.
Another possibility to set the value of a CSS property is to use the corresponding JavaScript property.
See the examples below for details.
To get the value of a style property, use the
To remove a style property, use the
object.setProperty (propertyName, propertyValue, priority);
You can find the related objects in the
section below.
Parameters:
propertyName
Required. String that specifies the name of the style property. This parameter is not case sensitive.
propertyValue
Required. String that specifies the value for the style property.
Required. String that specifies the priority of the style property. The priority of a style property can be retrieved by the
The priority can be one of the following values:
Set the important qualifier for the property.
empty string
Do not set the important qualifier for the property. The null value can also be used.
Return value:
This method has no return value.
Example HTML code 1:
This example illustrates the use of the setProperty method:
type"text/javascript"
function ModifyBGColor (button) {
if (button.style.setProperty) {
button.style.setProperty ("background-color", "green", null);
button.style.setAttribute ("backgroundColor", "green");
onclick"ModifyBGColor (this);" style"background-color:"Modify my background color!
Did you find this example helpful?
Example HTML code 2:
This example is equivalent to the previous one, but it uses the
style property to modify the background color of an element:
type"text/javascript"
function ModifyBGColor (button) {
button.style.backgroundColor = "green";
onclick"ModifyBGColor (this);" style"background-color:"Modify my background color!
Did you find this example helpful?
, htmlElement., htmlElement.HTML elements:, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
Related pages:
External links:
Del.icio.us
User Contributed Comments
Link To Us |
& . All rights reserved.下次自动登录
现在的位置:
& 综合 & 正文
OC中的一些关键术语&&@property assign retain copy的区别
类:是一种结构,它表示对象的类型,对象引用类来获取和本身有关的各种信息,特别是运行什么来处理每种操作。
对象:是一种结构,它包含值和指向其类的隐藏指针。
实例:对象的另一种称呼。
消息:是对象可以执行的操作,用于通知对象去做什么。对象接收消息后,将查询对应的类,以便查找正确的代码来运行。
方法:是为响应消息而运行的代码,根据对象的类,消息可以调用不同的方法。
接口:是对象的类应该提供特殊的特性的描述。
什么是property?
property是一种代码生成机制,能够生成不同类型的getter/setter函数,特别是如果你想要用点(.)操作符号来存取变量的话,你就能必须使用property。
如何使用?
用法如:@property (attribute1,attribute2)
这些attribute包括:
表示这个属性是只读的,就是只生成getter方法,不会生成setter方法。
readwrite 可读可写(默认)设置可访问级别。
assign:简单赋值,不更改索引计数
copy:建立一个索引数为1的对象,然后释放旧对象
retain:释放(release)旧对象,将旧对象的值赋予输入对象,再提高输入对象的索引计数为1
nonatomicnonatomic 非原子性访问,不加同步,多线程并发访问会提高性能。注意,如果不加此属性,
则默认是两个访问方法都为原子型事务访问。
前两个只是简单的设定变量的可读写性。
详细解释:copy其实是建立了一个相同的对象,而retain不是:
比如一个NSString对象,地址为0x1111,内容为@"STR" ,copy到另外一个NSString之后,地址为0x2222,内容相同,新的对象retain为1,旧有对象没有变化。
旧有对象没有变化。
retain 到另一个NSString之后,地址相同(建立一个指针,指针拷贝),内容当然相同,这个对象的retain值+1,也就是说,retain是指针拷贝,copy是内容拷贝。在拷贝之前,都会释放旧的对象。
assign:简单赋值,不更改索引计数(Reference Counting)。
copy:建立一个索引计数为1的对象,然后释放旧对象
retain:释放旧的对象,将旧对象的值赋予输入对象,再提高输入对象的输入对象的索引计数为1
使用assign:对基础数据类型(NSInteger)和C数据类型(int ,float,double,char等)
使用copy:对NSString
使用retain:对其他NSObject和其子类。
&&&&推荐文章:
【上篇】【下篇】评论 - 1133262728293031123456891011121314151617181920212223242526272829303112345
====Michael Lee====
=Java Sofware Engineer=
=Work @
---再烦,也别忘微笑;再急,也要注意语气;再苦,也别忘坚持;再累,也要爱自己!---
---低调做人,你会一次比一次稳健;高调做事,你会一次比一次优秀---
---成功的时候不要忘记过去;失败的时候不要忘记还有未来---
阅读排行榜
评论排行榜

我要回帖

更多关于 property copy 的文章

 

随机推荐