Javascript 选中复选框时执行函数
我有下面的功能,当我们选中或取消选中复选框(在gridview中)时,它将显示弹出窗口和其他处理信息 只有勾选了复选框而不是处于未勾选状态时,才有办法执行此功能吗 以下是我的职责:Javascript 选中复选框时执行函数,javascript,jquery,checkbox,jquery-events,Javascript,Jquery,Checkbox,Jquery Events,我有下面的功能,当我们选中或取消选中复选框(在gridview中)时,它将显示弹出窗口和其他处理信息 只有勾选了复选框而不是处于未勾选状态时,才有办法执行此功能吗 以下是我的职责: $(document).ready(function () { $('#<%= gvPRCertInfo.ClientID %> input[type="checkbox"]').change(function () { var signValue = $(
$(document).ready(function () {
$('#<%= gvPRCertInfo.ClientID %> input[type="checkbox"]').change(function () {
var signValue = $(this).closest('tr').children('td:eq(4)').html();
if (signValue == "Virtual") {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("you have selected virtual do u want to create a new name for this?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
});
});
if($("input").is(':checked')) {
dosomething
}
$(文档).ready(函数(){
$('#输入[type=“checkbox”]')。更改(函数(){
var-signValue=$(this.closest('tr').children('td:eq(4)').html();
如果(signValue==“虚拟”){
var confirm_value=document.createElement(“输入”);
确认\u value.type=“隐藏”;
确认价值。name=“确认价值”;
如果(确认(“您已选择虚拟,是否要为此创建新名称?”){
确认\u value.value=“是”;
}否则{
确认\u value.value=“否”;
}
document.forms[0].appendChild(确认值);
}
});
});
这是我的gridview:
<asp:GridView ID="gvPRCertInfo" runat="server" GridLines="None"
CssClass="data responsive">
<Columns>
<asp:TemplateField HeaderText="Select" SortExpression="">
<HeaderTemplate>
<asp:CheckBox ID="chkboxSelectAll" runat="server" AutoPostBack="true" OnCheckedChanged="chkboxSelectAll_CheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkCert" AutoPostBack="true" ClientIDMode="Static" OnCheckedChanged="chkCert_CheckedChanged" runat="server" />
<input type="hidden" id="hdnCertId" runat="server" value='<%# DataBinder.Eval(Container.DataItem, "CertId") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CertificateID" HeaderText="Certificate ID" HeaderStyle-HorizontalAlign="Center" />
................
.................
................
.................
请大家在我选中复选框时,就如何执行提出一些建议。在onchange函数中尝试一下这一点
if($(this).is(':checked') == true)
{
/* Your function code here.*/
}
Javascript代码
if(document.getElementById('mycheckbox').checked) {
console.log("ckecked")
} else {
console.log("not ckecked")
}
jquery代码
if ($('#mycheckbox').attr("checked")) {
console.log("ckecked")
}else{
console.log("not ckecked")
}
在onchange函数中尝试这一点 Javascript代码
if(document.getElementById('mycheckbox').checked) {
console.log("ckecked")
} else {
console.log("not ckecked")
}
jquery代码
if ($('#mycheckbox').attr("checked")) {
console.log("ckecked")
}else{
console.log("not ckecked")
}
你好,亲爱的,我想这会奏效,但我还是不确定 您可以编写如下代码:
$(document).ready(function () {
$('#myCheckbox').change(function () {
if ($(this).attr("checked")) {
// fire your function
return;
}
// not checked
});
});
你好,亲爱的,我想这会奏效,但我还是不确定 您可以编写如下代码:
$(document).ready(function () {
$('#myCheckbox').change(function () {
if ($(this).attr("checked")) {
// fire your function
return;
}
// not checked
});
});
在复选框的on change函数中尝试此操作
if($(this).is(':checked') == true)
{
/* Your function code here.*/
}
在复选框的on change函数中尝试此操作
if($(this).is(':checked') == true)
{
/* Your function code here.*/
}
您可以使用jQuery的is()函数:
$(document).ready(function () {
$('#<%= gvPRCertInfo.ClientID %> input[type="checkbox"]').change(function () {
var signValue = $(this).closest('tr').children('td:eq(4)').html();
if (signValue == "Virtual") {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("you have selected virtual do u want to create a new name for this?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
});
});
if($("input").is(':checked')) {
dosomething
}
您可以使用jQuery的is()函数:
$(document).ready(function () {
$('#<%= gvPRCertInfo.ClientID %> input[type="checkbox"]').change(function () {
var signValue = $(this).closest('tr').children('td:eq(4)').html();
if (signValue == "Virtual") {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("you have selected virtual do u want to create a new name for this?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
});
});
if($("input").is(':checked')) {
dosomething
}
使用
this.checked
属性,如果(!this.checked)返回,它将返回true
/false
使用this.checked
属性,如果(!this.checked)返回,则返回true
/false
代码>感谢您的支持:)感谢您的支持:)很抱歉,这台机器无法正常工作。。。谢谢你的支持为什么不工作你能给我一些反馈吗。。??“若要检索和更改DOM属性,例如选中的、选中的、禁用的表单元素的状态,请使用.prop()
方法。”很抱歉,此方法不起作用。。。谢谢你的支持为什么不工作你能给我一些反馈吗。。??“若要检索和更改DOM属性,如选中的、选中的、禁用的表单元素状态,请使用.prop()
方法。”感谢您的支持:)“若要检索和更改DOM属性,如选中的、选中的、禁用的表单元素状态,请使用.prop()
方法。”感谢您的支持:)“若要检索和更改DOM属性,如选中的、选中的或禁用的表单元素状态,请使用.prop()
方法。”感谢您的支持:)感谢您的支持:)