所以jQuery 1.6具有新功能prop().
$(selector).click(function(){
//instead of:
this.getAttribute('style');
//do i use:
$(this).prop('style');
//or:
$(this).attr('style');
})
Run Code Online (Sandbox Code Playgroud)
或者在这种情况下,他们做同样的事情?
如果我也有转用prop(),所有的旧attr()电话,如果我切换到1.6将打破?
UPDATE
selector = '#id'
$(selector).click(function() {
//instead of:
var getAtt = this.getAttribute('style');
//do i use:
var thisProp = $(this).prop('style');
//or:
var thisAttr = $(this).attr('style');
console.log(getAtt, thisProp, thisAttr);
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<div id='id' style="color: red;background: orange;">test</div>Run Code Online (Sandbox Code Playgroud)
(另见这个小提琴:http://jsfiddle.net/maniator/JpUF2/)
控制台会记录getAttribute作为一个字符串,并attr作为一个字符串,但prop作为一个CSSStyleDeclaration,为什么?这对我未来的编码有何影响?
我必须首先禁用输入,然后单击链接以启用它们.
这是我到目前为止所尝试的,但它不起作用:
HTML:
<input type="text" disabled="disabled" class="inputDisabled" value="">
Run Code Online (Sandbox Code Playgroud)
jQuery的:
$("#edit").click(function(event){
event.preventDefault();
$('.inputDisabled').removeAttr("disabled")
});
Run Code Online (Sandbox Code Playgroud)
这显示了我true,false但输入没有任何变化:
$("#edit").click(function(event){
alert('');
event.preventDefault();
alert($('.inputDisabled').attr('disabled'));
$('.inputDisabled').removeAttr("disabled");
alert($('.inputDisabled').attr('disabled'));
});
Run Code Online (Sandbox Code Playgroud) disabled文本框或文本区域的属性的正确值是什么?
我见过以下用过:
<input type="text" disabled />
<input type="text" disabled="disabled" />
<input type="text" disabled="true" />
Run Code Online (Sandbox Code Playgroud) 我已经阅读了JQuery文档,虽然很多注意力都集中在你应该传递的函数上,但是我没有看到任何关于它实际返回的信息.
特别是,它总是返回一个数组,即使只找到一个元素?没有找到任何东西时它会返回null吗?这记录在哪里?
我知道jquery方法可以应用于返回值,但是如果我想直接使用返回值呢?