您好我是Javascript代码的新手,似乎无法获得一些代码,任何帮助都会非常感激
我正在尝试使用函数参数将对象属性传递给if语句,如下所示:
function newmodalcontrols(modalspec) {
if (modelContentCall[modalspec].description == true) {
$(this).load('Content_for_injection.htm #description');
alert('description true2');
}
对象文字是modalContentCall
,具有嵌套属性。调用我想要的格式是:
modelContentCall.dynamicvariable.description
但我需要dynamicvariable
充满活力。
对于add_expense_se的对象属性,我的事件处理程序如下所示:
$('.add_expense_link').click(function() {
if($(this).attr('href')=="#add_expense_se") {
$(this).parent().next().find('.tailoredins').newmodalcontrols(add_expense_se);
}
我已经在文档就绪函数中定义了对象和我的所有代码。
再次感谢您的帮助。
答案 0 :(得分:0)
错误在于尝试将函数作为jQuery函数调用,其中它已被创建为JavaScript函数。我更改了第1行中的代码:
function newmodalcontrols(modalspec) {
到
$.fn.newmodalcontrols = function(modalspec) {
这允许在jQuery中正常调用函数,现在代码可以正常工作。