[英]How to toggle content of <td>?
I would very much like to be able to toggle having an x and not having an x in我非常希望能够在有 x 和没有 x 之间切换
<td class="checkbox"> <input name="signed" type="checkbox" checked /> x </td>
See JSFiddle for example例如,参见 JSFiddle
http://jsfiddle.net/littlesandra88/GMSCW/ http://jsfiddle.net/littlesandra88/GMSCW/
The code that is triggered when Submit is pressed is按下提交时触发的代码是
$('form').live('submit', function(){
$.post($(this).attr('action'), $(this).serialize(), function(response){
// do something here on success
},'json');
return false;
});
I assume I have to something in the lines of我想我必须做一些事情
$(this).getElementByClass("checkbox").td.toggle('x');
But checked
should still be updated in the <input name="signed" type="checkbox" checked />
但是
checked
还是应该在<input name="signed" type="checkbox" checked />
中更新
Does anyone know how to do this?有谁知道如何做到这一点?
Wrap the X in a span and then hide that将 X 包裹在一个跨度中,然后隐藏它
<td class="checkbox">
<input name="signed" type="checkbox" checked />
<span id='toggleme'>x</span>
</td>
//change the visibility of the x
$('#toggleme').toggle();
// check the checkbox
$('input[name=signed]').attr('checked', true);
To check a checkbox in jQuery use you ELEMENT.attr("checked","checked")
or the jQuery 1.6 way with ELEMENT.prop("checked", true)
要检查 jQuery 中的复选框,请使用
ELEMENT.attr("checked","checked")
或 jQuery 1.6 方式和ELEMENT.prop("checked", true)
The best idea, IMO, is to put a <label>
right next to the checkbox and then toggle
it with $("input[type=checkbox] + label", this).toggle()
.最好的主意,IMO,是在复选框旁边放一个
<label>
,然后用$("input[type=checkbox] + label", this).toggle()
toggle
它。
To change the checkbox, the examples other users gave work just fine.要更改复选框,其他用户提供的示例可以正常工作。
http://jsfiddle.net/w5nAr/ http://jsfiddle.net/w5nAr/
This assumes you don't want to change the checkbox, just the text next to it.这假设您不想更改复选框,只更改它旁边的文本。 If you want both, here's another example:
如果你想要两者,这是另一个例子:
$({some identifier for your checkbox}).attr("checked",true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.