prop

jQuery .prop() returns undefined, while .attr() works as expected for data-*

空扰寡人 提交于 2019-12-18 03:39:59
问题 I am simply trying to get a couple of properties from two elements. Getting the property value from the input element works as expected. The problem is with getting the property data-detail property from the button element. It returns undefined when using .prop() , but works as expected when using .attr() . Can anyone explain this odd behaviour I am witnessing? HTML <div class="formRow"> <label for="firstName">First name</label> <div class="detailsControlBtns"> <button id="editFirstName"

difference between prop() and attr() in jQuery and when to use attr() and prop() [duplicate]

徘徊边缘 提交于 2019-12-17 02:10:30
问题 This question already has answers here : .prop() vs .attr() (17 answers) Closed 6 years ago . I saw in some places .attr() is used in jQuery.In some places .prop() is used.But i searched in SO and google i am very confused .Please tell me the exact difference between these two and when to use them. I have seen the following links jQuery attr vs. prop, there are a list of props? jQuery attr vs prop? But I did not got the answer.Please help me.Thanks in advance. Before giving a downvote please

Using jQuery .attr or .prop to set attribute value not working

一世执手 提交于 2019-12-14 03:41:59
问题 I've created a button with attribute named 'loaded' and initial value of 'no'. Upon clicking the button I'm running some ajax and at the very end of it I'm trying to set the 'loaded' attribute to 'yes' so that the ajax is not ran again if the user clicks on the button more than once. I have something like this: http://jsfiddle.net/PDW35/2/ Clicking the button does not change loaded to 'yes'. However, if you do an alert right after the .attr call like this: alert($(this).attr('loaded')); the

Calling functions after state change occurs in reactjs

匆匆过客 提交于 2019-12-09 18:06:13
问题 My question is this. I have two components. First component is an image cropper. Second component is the one that i should display the cropped image. The problem i'm facing is i can pass the cropped image to my second component but i have to press the button that crops the image and pass to the second component, twice. On the second click only my image is passing to the second component. But i can display the cropped image in the first component only by one click. I think it is happening

jQuery .prop(“disabled”, false) not working in Chrome

删除回忆录丶 提交于 2019-12-08 14:36:19
问题 having problems with .prop("disabled", false) it's works fine in opera and firefox but IE and chrome i can't get it to work.. Actualy it's a invination form and im make send button like this <input id="sendInvite" class="mail_send" disabled="disabled" type="button" name="invite" value="Send"> and here is css .mail_send[disabled="disabled"] {background-color:#343434; color:#747474} So as you can see button is disabled and you can't click, you must first write your name and mail after that

jquery 中prop的使用以及一些要注意的问题

我怕爱的太早我们不能终老 提交于 2019-12-06 19:03:20
近有网友提出jquery做全选和取消全选这些操作时,只能执行一遍,后面追查下去,发现了问题的根源,发现用jquery中的removeProp对checked操作是会完全移除了元素的属性,以至于使用removeProp后再使用prop设置属性就没有效果了?? 于是查找到了官网,终于发现了 Do not use this method to remove native properties such as checked, disabled, or selected. This will remove the property completely and, once removed, cannot be added again to element. Use .prop() to set these properties to false instead. 这是jquery中的说明 http://api.jquery.com/removeProp/ 于是html是可以这样的 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>prop的使用</title> </head> <body> <label><input type=

jQuery 1.9版本以上多次点击checkbox无法选中的问题

我是研究僧i 提交于 2019-12-06 19:03:08
问题描述:全选功能 代码: $("input[name='onday[]']").each(function(){ $(this).attr('checked','checked'); }); 第一次 全选和全不选 能很好的工作,但第二次开始 不能全选 将checked改为 true false也不好使 网搜之,说是jQuery版本问题,且使用prop能很好地工作, 代码更简练 $("input[name='onday[]']").prop('checked',$('#checkedall').prop('checked')); so以后像checkbox,select 这种请一律使用 prop方法,good。 参考: http://www.imuum.com/jquery-more-than-1-9-times-click-on-the-checkbox-cannot-be-selected.html 来源: oschina 链接: https://my.oschina.net/u/26712/blog/526849

jquery prop方法的使用以及与attr方法的区别

对着背影说爱祢 提交于 2019-12-05 19:52:50
prop方法的概况: prop()是jquery1.6中新加了一个方法,用来区分attr方法,专门用来处理DOM属性。一些内置属性的DOM元素或window对象,如果试图将删除该属性,浏览器可能会产生错误,而prop方法则可以避免这种错误发生。换言之,prop可以说是为了处理DOM属性(如 selectedIndex, tagName, nodeName, nodeType, ownerDocument, defaultChecked, 和 defaultSelected)而产生的。 prop的用法: 返回属性的值: $(selector).prop(property) // EXP <input type=‘checkbox’> <button>查看</button> <script> $(“button”).click(function(){ $(“input”).prop(‘checked’); }); //input选中点“查看”返回true //input未选中点“查看”返回false </script> 设置属性和值: $(selector).prop(property,value) // EXP <input type=‘checkbox’> <button>选中</button> <script> $(“button”).click(function(){ $(

Using jQuery .attr or .prop to set attribute value not working

℡╲_俬逩灬. 提交于 2019-12-04 07:11:58
I've created a button with attribute named 'loaded' and initial value of 'no'. Upon clicking the button I'm running some ajax and at the very end of it I'm trying to set the 'loaded' attribute to 'yes' so that the ajax is not ran again if the user clicks on the button more than once. I have something like this: http://jsfiddle.net/PDW35/2/ Clicking the button does not change loaded to 'yes'. However, if you do an alert right after the .attr call like this: alert($(this).attr('loaded')); the alert box does contain 'yes' which doesn't help because once the user clicks, the same code above puts

jquery attr prop checkbox已有checked=checked但不显示勾选问题

青春壹個敷衍的年華 提交于 2019-12-01 18:05:15
最近在做项目的过程中碰到了这样的一个问题:在使用bootstrap模态框的过程中,在模态框中有一个checkbox标签,一开始是为选中的,当点击触发模态框按钮,选中chcekbox时,会显示勾选,这个时候将选中的状态缓存起来,然后点击模态框中的关闭按钮,再次点击触发模态框按钮弹出模态框,这个时候问题出现了: checkbox标签已有checked=checked但是不显示勾选,查看图片: 网上也查过有解决方案,就是将 $("...").attr("checked", true)改为$("...").prop("checked", true),问题解决,但是,问题是解决了,那么原因是出现在哪里呢? 首先来了解下 jquey中的 attr()函数和prop()函数,attr()是处理 attribute的值的,而prop()是处理 property 的值的 ,jQuery 1.6之前 ,.attr()方法在取某些 attribute 的值时,会返回 property 的值,这就导致了结果的不一致。从 jQuery 1.6 开始, .prop()方法 方法返回 property 的值,而 .attr() 方法返回 attributes 的值,那么归根结底,就是在处理 attribute 和 property。 很多attribute节点有一个相应的property属性