jquery中attr()和prop()的区别

从零上手:基于英飞凌TC377的UDE STK 5.0实战调试指南 本文详细介绍了基于英飞凌TC377芯片和UDE STK 5.0的实战调试指南,涵盖硬件连接、工作空间配置、程序烧录、多核调试等关键步骤。特别针对汽车电子领域常见的多核架构调试难题,提供了断点设置、变量监控等实用技巧,帮助开发者快速上手并优化调试效率。 阅读详情

我理解的jquery中attr()和prop()的区别

查了很多资料,官方解释如下:

– attr() 方法设置或返回被选元素的属性和值。
– prop() 方法设置或返回被选元素的属性和值。

???此处自动脑补黑人问号脸!!!我真的不理解啊!!!有区别吗这两句话?!
还有一句解释:

注意:prop() 方法应该用于检索属性值,例如 DOM 属性(如 selectedIndex, tagName, nodeName, nodeType, ownerDocument, defaultChecked, 和 defaultSelected)。
提示:如需检索 HTML 属性,请使用 attr() 方法代替。

然后给了一个例子,大概明白了一点点:

attr()返回的是“属性”的值,就是能在html中看到的属性,如:

<input id="check1" type="checkbox"  >
$("input").attr('checked')	#undefined

<input id="check1" type="checkbox" checked="checked" >
$("input").attr('checked')	#checked

prop()返回的是JS对象属性的“值”,只能看到属性的值(true,false),如:

<input id="check1" type="checkbox"  >
$("input").prop('checked')	#false

<input id="check1" type="checkbox" checked="checked" >
$("input").prop('checked')	#true

以下为文档https://segmentfault.com/a/1190000002680303中的引用,说的很详细

★★★★★
对于表单元素的checked、selected、disabled等属性,在jQuery 1.6之前,attr()获取这些属性的返回值为Boolean类型:如果被选中(或禁用)就返回true,否则返回false。
★★★★★
但是从1.6开始,使用attr()获取这些属性的返回值为String类型,如果被选中(或禁用)就返回checked、selected或disabled,否则(即元素节点没有该属性)返回undefined。并且,在某些版本中,这些属性值表示文档加载时的初始状态值,即使之后更改了这些元素的选中(或禁用)状态,对应的属性值也不会发生改变。
因为jQuery认为:attribute的checked、selected、disabled就是表示该属性初始状态的值,property的checked、selected、disabled才表示该属性实时状态的值(值为true或false)。

因此,在jQuery1.6及以后版本中,请使用prop()函数来设置或获取checked、selected、disabled等属性。对于其它能够用prop()实现的操作,也尽量使用prop()函数。

综上,我的问题就是因为我要增加一个class并且让按钮失效后无法点击,给html设置了一个disabled属性,使用prop()会导致设置的值实际上是true,而使用attr()才能保证设置的值是html属性中的disabled
以下分别是我使用attr()和prop()设置属性的html属性值展示结果:
attr()
attr("disabled",true)
prop()
prop("disabled",true)

STM32(HAL库)软件IIC驱动OLED 本文通过STM32F103C8T6单片机(HAL库)通过软件IIC方式对OLED进行驱动。 阅读详情

相关推荐

【Qt】Qt5.15在线安装避坑指南:从代理配置到组件选择的完整实践

本文详细介绍了Qt5.15在线安装的全流程避坑指南,包括代理配置、组件选择和常见问题解决方案。通过使用Fiddler工具和国内镜像源,可显著提升下载速度。文章还提供了组件选择的黄金法则和安装后的验证步骤,帮助开发者高效完成Qt5.15的安装与配置。

weixin_42550052的博客 266

attr和prop选取渲染的区别

1. 有true, false两个属性的使用prop()方法,如(checked, selected, disabled,readonly, multiple, location, async, autofocus)使用layui的单选按钮控件时,单选按钮赋值错误,第一次打开弹出层编辑信息后,单选按钮是正常渲染的。第二次打开另一条信息的弹出层,发现单选按钮显示的值没有正常渲染,而是显示上一次修改后弹出层的值。不同点:attr没有对应的属性值返回undefined,而prop没有对应的属性值返回空串。

菜鸟的博客 435

分子模拟入门教程 | 低调使用 建议收藏

该方法只需要原子的核电荷和少数模拟的环境参数作为输入,所有的性质都是通过求解薛定谔方程得到的,不需要使用任何经验参数。经典的原子水平的分子模拟已经成为提高我们对材料科学和生命系统中分子过程理解的最流行的方法之一。全原子模拟是一种非常强大的以原子分辨率呈现信息的方法,因为在原子模拟中,一个粒子代表一个特定的原子。随着计算机硬件和模拟技术的快速发展,分子模拟不仅可以解决基本的、常规的化学问题,还可以应用于各种复杂体系。然而,由于问题的复杂性以及严重依赖于现象的现实情况,最好是逐案确定合适的模拟方法。

pysonger的博客 777

jquery中关于attr和prop的区别!

昨天这两个方法搞混了,被公司大佬说了下,虽然没说什么,但还是挺尴尬的。重点是大佬说你可以用attr方法,我特么第一句话就是怎么用呢。原谅我使用vue之后太依赖框架的东西了,以至于以前jquery玩的也挺溜的我,慢慢淡忘了 jquery。罪过罪过呢!jquery还是一款很优秀的函数库,哎 不说了 继续码代码了。 $().attr() 允许我们往元素上加上自定义属性 我们也可以用attr 获取提前定义好的在上面的 自定义属性值 当然 也可以获取到 元素 自带的一些属性 那么 attr 是获取和设置 属性的

Java&Develop的博客 5985

FPGA新手避坑指南:手把手教你搞定RTL8211千兆网PHY的时序配置(附Verilog代码)

本文详细解析了FPGA与RTL8211千兆网PHY芯片的时序配置问题,重点介绍了TXDLY/RXDLY引脚设置、FPGA发送端和接收端的Verilog实现,以及调试与验证的完整流程。通过硬件电路设计和代码示例,帮助开发者解决网络连接不稳定、丢包等常见问题,提升千兆网通信的稳定性。

weixin_28732953的博客 534

JS中attr 和 prop 的区别

attr : 设置或返回被选元素的属性值. prop : 获取在匹配的元素集中的第一个元素的属性值。 attr 和 prop 的本质 attr 是 attribute 的缩写,prop 是 property 的缩写,都有属性的意思,只不过 attr 是操作 html 文档节点属性,prop 是操作 js 对象属性. attr 在 js 中使用的是 setAttribute 和 getAttribute 而 prop 直接使用原生 js 的 element[value] 和 element[value]=ke

weixin_49199038的博客 5124

[系统安全] 十六.PE文件逆向基础知识(PE解析和PE编辑工具)

您可能之前看到过我写的类似文章,为什么还要重复撰写呢?只是想更好地帮助初学者了解病毒逆向分析和系统安全,更加成体系且不破坏之前的系列。因此,我重新开设了这个专栏,准备系统整理和深入学习系统安全、逆向分析和恶意代码检测,“系统安全”系列文章会更加聚焦,更加系统,更加深入,也是作者的慢慢成长史。换专业确实挺难的,逆向分析也是块硬骨头,但我也试试,看看自己未来四年究竟能将它学到什么程度,漫漫长征路,偏向虎山行。享受过程,一起加油~ 作者前面介绍了三个漏洞,包括Chrome浏览器保留密码渗透解析、通过Chrome浏

杨秀璋的专栏 1万+

jquery中attr和prop的区别

一,获取属性的区别 ● attr() 操作标签上的属性 ● prop() 操作Boolean类型的属性和有特性(class id name)的属性 attr可以操作HTML标签中的属性,不管是固有属性,还是添加的自定义属性。都可以通过attr来设置。 prop同样可以操作HTML中的固有属性,但对于自定义属性便无能为力了 下图可见 对于标签的固有属性,建议用prop方法。 如 id,class,width; 获取标签属性。 对于标签的自定义属性,建议使用attr方法。 二,获取属性值为boolean类型

m0_47720236的博客 3527

TGAT Python:图神经网络中的动态图算法

其中,图神经网络中的动态图算法成为了研究的热点之一。在模型的 forward 方法中,通过循环调用 TGATLayer 实例来进行图神经网络的前向传播。最终,模型返回图中节点的表示向量 output,可以用于图分类等任务。TGAT 算法的核心思想是在节点之间建立注意力连接,以捕捉节点在不同时间步之间的关系。TGAT 算法通过引入注意力机制和时间信息,从而有效地对动态图数据进行建模和分析。通过以上 Python 代码,我们可以方便地构建和训练 TGAT 模型,并在图分类任务中应用它。

2301_79366435的博客 1820

《网络安全自学教程》- 防火墙原理分析与Windows防火墙使用配置

防火墙分类及原理,Windows开启防火墙,Windows防火墙添加策略,

wangyuxiang946的博客 1万+

prop和attr的区别

prop和attr的选择

wxqwxq123444的博客 3236

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

jQuery中attr()与prop()的区别

Write By Monkeyfly 以下内容均为原创,如需转载请注明出处。 前提 在 jQuery 里,我们要获取一个标签元素的属性,可以用 attr()方法或者 prop()方法 ,那么两者有什么区别呢? jQuery attr() 方法 和 prop() 方法 attr() 方法设置或返回被选元素的属性值。 prop() 方法设置或返回被选元素的属性和值。 注:单纯从定义看的话,两个方法...

monkeyfly学前端 8709

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

jQuery中attr()和prop()的区别与使用

API attr()系列 attr(attributeName) 读取第一个匹配到的元素的指定属性值。 attr(attributeName, value) 设置单个指定的属性值。 attr(attributes) 设置多个。 attr(attributeName, func) func为function(index, thisAttr)。 prop(...

wuyujin1997的博客 1万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

JQuery中attr()和prop()用法和区别

JQuery中attr()和prop()用法和区别

Java仗剑走天涯 4453

jQuery之attr()和prop()的区别

attr()与prop() 都具有设置和获取属性值的功能,但还是有所不同,下面就来解释一下吧

Tom197的博客 921

JQuery函数attr()和prop()的区别

JQuery函数attr()和prop()的区别   attr()函数和prop()函数都用于设置或获取指定的属性,它们的参数和用法也几乎完全相同。 操作对象不同应用版本不同用于设置的属性值类型不同其他细节问题 操作对象不同   attr和prop分别是单词attribute和property的缩写,并且它们均表示"属性"的意思。 …………………………………………………………………………………………………………   在jQuery中,attribute和property却是两个不同的概念。attribut

weixin_45846980的博客 2737

jQuery实战之 attr() 和 prop() 的区别

是不是刚开始学jQuery的时候,看到了这两个方法:attr()和prop();感觉这不是一个意思吗?他们有什么区别呢? 下面简单的给大家区分一下: 对于HTML元素本身就带有的固有属性,在处理的时候,使用prop()方法。 对于HTML元素我们自己自定义的DOM属性,在处理时,使用attr()方法。 举例说明 <a href="http://www.baidu.com" target="_self" class="btn">百度</a> 这个例子里a元素的DOM属性有href、

xiaoxijinger的博客 267

jquery中html()、css()、prop()和attr()区别

xiaobai_IT_learn的博客 292

JQUERY ATTR()和PROP()方法的区别

JQUERY ATTR()和PROP()方法的区别 $(’’).attr()返回的是html对象 $(’’).prop()返回的是DOM对象 attr(): attr() 方法设置或返回被选元素的属性和值。 当该方法用于返回属性值,则返回第一个匹配元素的值。 当该方法用于设置属性值,则为匹配元素设置一个或多个属性/值对。 方法操作adio(checkbox)之类的控件,让其选中的时候,其控件选中的...

泊一的博客 165

jQuery中attr()和prop()方法的区别

jQuery中attr()和prop()方法的区别 两者皆是设置或返回被选元素的属性和值。 方法也类似。 1.当小括号中为两个参数时,是设置属性的属性值。 2.当小括号中为一个参数时,为获取该元素的属性值。 $(function () { $("#btn").click(function () { $("a").attr("titile",百度); //设置属...

从入门到放弃_nys的博客 192

jquery的attr()和prop()方法的区别;

attr()&prop() prop() 和 attr() 之间的不同 prop() 和 attr() 可能返回不同的值。本实例演示了当用于返回复选框的 “checked” 状态时的不同。 prop() --> true attr —> checked 在jQuery中,attr()函数和prop()函数都用于设置或获取指定的属性,它们的参数和用法也几乎完全相同。 但不得不说的是,这两个函数的用处却并不相同。下面我们来详细介绍这两个函数之间的区别。 1、操作对象不同 很明显,attr和p

yyjiuguilian的博客 310

jQuery中html()、text()和val()的区别、jQuery中attr()和prop()的区别

jQuery中html()、text()、val()的区别 html():向匹配的元素中添加html标记。比如、等html标签。添加的元素将覆盖原有的元素内容。 text():向匹配的元素中添加文本。如果文本包含html标签将会以文本的形式输出。添加的文本将会覆盖原有的元素内容。 val():设置或者获取DOM元素的value属性值。比如:获取input元素的value值,代码如下: $

fly_zxy的专栏 3081

jQuery 中 attr() 和 prop() 方法的区别

.prop()方法只获得第一个匹配元素的属性值 。如果元素上没有该属性,或者如果没有匹配的元素。那么该方法会返回undefined值。若要取得每个匹配元素的属性值(property),请使用循环结构,如jQuery.each()或.map()方法。 attributes和properties之间的差异在特定情况下是很重要。jQuery 1.6之前,.attr()方法在取某些 attribut...

qq_36031730的博客 158

jquery中attr()与prop()区别

  我们知道jquery中获取元素属性有两种常见的方法,一个是attr()方法,这个是用的比较多的,也是我们第一个想到的。另外一个就是prop()方法了,这个方法之前很少用到,它是jquery1.6之后新增的方法。那么这两个方法都是获取属性的,那么神马区别呢?闲话不多说,下面我们就来说说。   首先从单词解释来说attr和prop分别是单词attribute和property的缩写,它...

aijinxia1968的博客 145
上一篇: layui踩坑总结
下一篇: python中*args和**kwargs的区别
猫柠
博客等级 码龄9年 9粉丝 21原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值