Jquery attr还是道具?

时间:2014-06-06 02:42:49

标签: jquery asp.net vb.net

我有一些来自代码背后的自定义属性。

我使用

添加它们
 sender.Attributes.Add("TextLinkNo", sender.TextLinkNo)
        sender.Attributes.Add("TextHeader", sender.TextHeader)
        sender.Attributes.Add("TextDisplay", sender.TextDisplay)
        sender.Attributes.Add("FSize", sender.FSize)
        sender.Attributes.Add("iRotation", sender.iRotation)
        sender.Attributes.Add("PrintStatus", sender.PrintStatus)
        sender.Attributes.Add("Parameter", sender.Parameter)
        sender.Attributes.Add("SupportDEC", sender.SupportDEC)

html代码

<span id="ctl00_ContentPlaceHolder1_LabelAttributes1_TabContainer1_TabPanel1_08" 
itextstyle="0" asign="0" supportdec="0" linetp="0" textlinkno="0" parameter="0" 
supportfontsize="False" class="draglabel ui-draggable ui-resizable" printstatus="7" 
spaceadjust="0" irotation="0" actc5="False" index="8" fieldformat="C1" ifontstyle="0" 
stringstatus="0" fsize="-1" ialign="0" textdisplay="Commodity Name" textheader="False" 
istartline="0" style="position: absolute; border-style: solid; border-width: 1px; left: 9px; top: 205px; width: 476px; height: 174px; background-color: rgb(255, 192, 203);" top="8" left="19">
Commodity Name
<div class="ui-resizable-handle ui-resizable-e" style="z-index: 90;"></div><div class="ui-resizable-handle ui-resizable-s" style="z-index: 90;"></div><div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 90;"></div></span>

我可以使用

获取这些属性
$(this).attr("supportdec");

但不是

$(this).prop("supportdec");
$(this).prop("data-supportdec");

i tot prop支持attr支持+附加?

1 个答案:

答案 0 :(得分:1)

已经提出了许多问题,哪些文件记录了.attr().prop()之间的区别。

我建议您阅读StackOverlfow post

jQuery api中.prop() api中记录的差异也是located here.

以下是从上面提到的jQuery网站中提取的。

  

属性与属性

     

属性和属性之间的区别非常重要   具体情况。在jQuery 1.6之前,有时会使用.attr()方法   在检索某些属性时考虑了属性值,   这可能会导致行为不一致。从jQuery 1.6开始,.prop()   方法提供了一种显式检索属性值的方法   .attr()检索属性。

     

例如,应检索selectedIndex,tagName,nodeName,nodeType,ownerDocument,defaultChecked和defaultSelected   并使用.prop()方法设置。在jQuery之前   1.6,这些属性可以使用.attr()方法检索,但这不在attr的范围内。这些没有相应的   属性,只是属性。

     

根据W3C表单规范,checked属性为a   boolean属性,表示相应的属性为true   该属性完全存在 - 即使例如属性   没有值或被设置为空字符串值甚至“假”。这是   所有布尔属性都是true。

     

然而,最重要的概念要记住检查   属性是它与checked属性不对应。该   attribute实际上对应于defaultChecked属性和   应该只用于设置复选框的初始值。该   checked属性值不随状态而变化   复选框,而checked属性。因此,   跨浏览器兼容的方式来确定是否选中了复选框   使用该财产。

相关问题