我想做这样的事情来勾选checkbox使用jQuery:
$(".myCheckBox").checked(true);
Run Code Online (Sandbox Code Playgroud)
要么
$(".myCheckBox").selected(true);
Run Code Online (Sandbox Code Playgroud)
这样的事情存在吗?
所以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,为什么?这对我未来的编码有何影响?
我想设置一个单选按钮.我想通过使用值或id来设置它.
这就是我尝试过的.
$('input:radio[name=cols]'+" #"+newcol).attr('checked',true);
Run Code Online (Sandbox Code Playgroud)
newcol 是单选按钮的ID.
也许有点编辑.
有两组收音机盒,一组带有cols,另一组带有行.所以我看到了不使用id的观点.我的错.所以我举个例子:
<input type="radio" name="rows" class="listOfCols"
style="width: 50%; " value="Site"></input>
Run Code Online (Sandbox Code Playgroud)
和
<input type="radio" name="cols" class="listOfCols"
style="width: 50%; " value="Site"></input>
Run Code Online (Sandbox Code Playgroud)
删除了id,我需要设置正确的ID.
在jQuery 1.9 v复选框未选中,一旦我取消选中它,尝试通过单击按钮再次检查
$("#add_cart_checkbox").attr("checked",'checked') ;
Run Code Online (Sandbox Code Playgroud) 在我的页面中,我有三个单选按钮,我想在单击时检查单选按钮<li>.我的点击功能正在运行,但点击时未检查收音机.我怎样才能做到这一点?我的代码如下
$(document).ready(function() {
$('#myContainer li').click(function() {
$('#radio1').attr('checked');
});
});
<div id="myContainer">
<li id="li1">
<input id="radio1" name="RadioGroup" value="val1" type="radio">
val1
</li>
<li id="li2">
<input id="radio2" name="RadioGroup" value="val2" type="radio">
val2
</li>
<li id="li3">
<input id="radio3" name="RadioGroup" value="val3" type="radio">
val3
</li>
</div>
Run Code Online (Sandbox Code Playgroud) 我有一个带有两个按钮的jquerymobile页面.一两个选中所有复选框,一个选中取消选中所有复选框.我第一次点击check all它有效,但在取消选中之后它不再有效.
这是我的代码:
<div data-role="page" id="selecttest">
<div data-role="header">
<a href="#sc" data-icon="home">SSC</a>
<h1>...</h1>
</div><!-- /header -->
<div data-role="content">
<fieldset class="ui-grid-a">
<div class="ui-block-a"><button onclick="$('#selecttest input[type=checkbox]').attr('checked','checked').checkboxradio('refresh');" data-theme="b">check all</button></div>
<div class="ui-block-b"><button onclick="$('#selecttest input[type=checkbox]').removeAttr('checked').checkboxradio('refresh');" data-theme="b">uncheck all</button></div>
</fieldset>
<fieldset data-role="controlgroup">
<input type="checkbox" name="checkbox-v-2a" id="checkbox-v-2a">
<label for="checkbox-v-2a">One</label>
<input type="checkbox" name="checkbox-v-2b" id="checkbox-v-2b">
<label for="checkbox-v-2b">Two</label>
<input type="checkbox" name="checkbox-v-2c" id="checkbox-v-2c">
<label for="checkbox-v-2c">Three</label>
</fieldset>
</div>
</div><!-- /page -->
Run Code Online (Sandbox Code Playgroud)
我正在使用jQuery 1.9.1和jQuerymobile 1.3
我已经看过如何选择或取消选择JQuery Mobile中的所有复选框?但它没有帮助我.
jquery ×6
javascript ×2
attr ×1
checkbox ×1
checked ×1
dom ×1
prop ×1
radio-button ×1
selected ×1