所以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,为什么?这对我未来的编码有何影响?
我需要jQuery选择器的帮助.假设我有一个标记,如下所示:
<form>
<table>
<tr>
<td><input type="checkbox" id="select_all"/></td>
</tr>
<tr>
<td><input type="checkbox" name="select[]"/></td>
</tr>
<tr>
<td><input type="checkbox" name="select[]"/></td>
</tr>
<tr>
<td><input type="checkbox" name="select[]"/></td>
</tr>
</table>
</form>
Run Code Online (Sandbox Code Playgroud)
除了#select_all用户点击它之外,如何获取所有复选框?
任何帮助将不胜感激.
我在Web应用程序上工作,在运行时,我的代码甚至无法工作.但如果这样做
$("input[name^='show-points-']").attr("checked", false);
Run Code Online (Sandbox Code Playgroud)
在控制台上,复选框取消选中.
奇怪,因为,总是在控制台:
$("input[name^='show-points-']").attr("checked", "checked");
Run Code Online (Sandbox Code Playgroud)
不行.
在这个Jsfiddle中,代码适用于"取消选中"功能,但不适用于"全部检查"功能.
我有一个复选框,我正在使用jQuery检查和取消选中,但是我遇到了大多数主流浏览器的错误:
如果我更改要检查的复选框,然后取消选中,然后再使用jquery再次检查,即使检查元素已正确添加checked属性,小十字也不再显示.
我使用以下代码更改了checked属性:
$('.checkbox').attr('checked', true);
Run Code Online (Sandbox Code Playgroud)
替换false取消选中框.
有没有人遇到过这个问题或知道如何绕过它?
这是一个复制问题的小提琴 - 单击检查,然后取消选中然后再次检查,您将看到不再出现勾号