jquery,嵌套 div 中的复选框 onclick 显示/隐藏提交
我的页面在购物车系统中包含一系列 div。每个都是一个产品,在检查复选框时,如果有可用选项和/或在表单提交之前要确认的确认复选框,则保持按钮隐藏并显示一个带有另一个复选框的 div,当该复选框(如果存在)被选中时然后显示按钮。 每个 div 上的显示隐藏工作正常(现有代码),因此我尝试创建一个在该函数中为 onclick 事件调用的函数。
我的问题出现的地方是检查另一个复选框[在示例中显示为(tmpId ==“acknowledge”)]是否存在,并且在他们可以看到提交按钮之前也检查它,如果不显示提交按钮。这需要适用于他们点击 [ie("id= "+feeSID+"_checkbox")
] 上第一个复选框的每个产品... $("#ocContainer") 是隐藏容器(带有提交),用于显示是否选中了正确的复选框..对于每个选定的产品。
每个 id 的第一部分是由 sql 查询生成并传递给函数的变量。 我的职能:
var feeSID = "";
var feeVAL = "";
var pop = "";
function countChecked(feeSID) {
var n = $("input:checked").val();
var tmpId = $(this).attr("name");
if (tmpId == "acknowledge") {
console.log("acknowledge Clicked <br />");
} else {
feeVAL = $(this).attr("id");
}
if (feeVAL == '') {
return;
} else {
if ($("#" + feeSID + "_checkbox:checked")) {
console.log("id= " + feeSID + "_checkbox");
var pop = $("#" + feeSID + "_popup").length;
if (pop > 0) {
$(":checkbox").click(function () {
if (tmpId == "acknowledge") {
$("#ocContainer").show();
}
});
} else {
$("#ocContainer").show();
}
}
}
}
我希望我的解释很清楚。我收到以下错误:未捕获的异常:语法错误,无法识别的表达式:#[object Object]_popup
I have a page that has a series of div's in a shopping-cart system. Each is a product, when checking the checkbox, if there are options available and/or an acknowledge checkbox to be acknowledged before form submit, then keep the button hidden and show a div with another checkbox in it, when that checkbox if exists is checked then show button.
The show hide on each div is working properly (existing code), So I am trying to create a function to be called within that function for the onclick event.
where my issue arises is the check to see if another check box [shown in the example as(tmpId == "acknowledge")] does exist and that it is checked also before they can see the submit button, if not show the submit button. This would need to work for each product they click the first checkbox on [ie("id= "+feeSID+"_checkbox")
]... $("#ocContainer")
is the hidden container(with submit) to show if proper checkboxes are checked.. for each product selected.
the first part of each id is a variable generated by a sql query and passed to the function..
My Function:
var feeSID = "";
var feeVAL = "";
var pop = "";
function countChecked(feeSID) {
var n = $("input:checked").val();
var tmpId = $(this).attr("name");
if (tmpId == "acknowledge") {
console.log("acknowledge Clicked <br />");
} else {
feeVAL = $(this).attr("id");
}
if (feeVAL == '') {
return;
} else {
if ($("#" + feeSID + "_checkbox:checked")) {
console.log("id= " + feeSID + "_checkbox");
var pop = $("#" + feeSID + "_popup").length;
if (pop > 0) {
$(":checkbox").click(function () {
if (tmpId == "acknowledge") {
$("#ocContainer").show();
}
});
} else {
$("#ocContainer").show();
}
}
}
}
I hope my explanation was clear. I am getting an error of:uncaught exception: Syntax error, unrecognized expression: #[object Object]_popup
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为异常可能是由代码中的这一行引起的:
在代码中的某个时刻,feeSID 被分配给一个对象。因此,您尝试使用对象而不是字符串作为选择器的一部分。在尝试将其用作选择器的一部分之前,您需要确保 FeeSID 是字符串而不是对象。
I think that the exception is possibly caused by this line in your code:
At some point in your code, feeSID is assigned to an object. So, you are trying to use an object as part of your selector rather than a string. You need to make sure that feeSID is a string rather than an object before you try using it as part of the selector.
该错误是由于我尝试使用 Obj 作为选择器的一部分引起的。正如 Adam Prax 所指出的,
在我的代码中的某个时刻,feeSID 被分配给一个对象。我通过将变量或对象重新声明为字符串来解决这个问题,然后使用
new String(feeSID);
再次访问它
这解决了这个问题。我希望它对其他人有帮助,我在 google 上找到的所有内容都指向语法
@name="name"
的使用,这在 jQuery 中不再是有效的语法。The error was caused by me trying to use an Obj as part of my selector. As Adam Prax had pointed out
At some point in my code, feeSID is assigned to an object. I solved it by redeclaring the Variable or Object as a string before accessing it again using
new String(feeSID);
This solved the issue. I hope it helps someone else, all I could find on google pointed to the use of the syntax
@name="name"
which is no longer valid syntax in jQuery.