0

嗨,我对 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);
    }

我已经在文档就绪函数中定义了对象和我的所有代码。

再次感谢任何帮助。

4

1 回答 1

0

错误在于尝试将该函数调用为 jQuery 函数,而该函数已被创建为 JavaScript 函数。我将第 1 行中的代码更改为:

function newmodalcontrols(modalspec) {

$.fn.newmodalcontrols = function(modalspec) {

这允许在 jQuery 中正常调用该函数,并且代码现在可以正常工作。

于 2013-05-22T17:11:43.053 回答