加载后修改Javascript对象

时间:2012-07-03 13:57:21

标签: javascript jquery

我试图在页面加载后修改对象,这样我就可以在不编辑核心文件的情况下更改脚本:

我尝试了什么:

<script type="text/javascript">
joms.status.Creator['submit'] =function(){

  var message = CreatorMessage.hasClass('hint') ? '' : CreatorMessage.val();

  attachment = (CurrentCreator.getAttachment) ? CurrentCreator.getAttachment() : {};

  attachment.privacy  = Creator.Privacy.find('option:selected').val();
  attachment.target   = ActivityTarget;
  attachment.element  = ActivityType;
  attachment.filter   = ActivityList.find('#activity-type').val();
  attachment.connection = $('#connectionid').val();
  Status.add(message, attachment);
} 
</script>

我正在尝试更改提交功能以专门添加此行:

attachment.connection = $('#connectionid').val();

原始脚本加载如下:

(function($) {

var Status,
    StatusUI,
    CreatorViews,
    CreatorMessage,
    CreatorPrivacy,
    CreatorLocation,
    CreatorShareButton,
    CreatorLoadingIndicator,
    InitialCreator,
    CurrentCreator,
    ActivityTarget,
    ActivityType,
    ActivityContainer;

joms.extend({
    status:
    {
        Creator : {},

        submitting: false,

        initialize: function(options)
        {
            ......
        },

        create: function(CreatorUI)
        {   .....
        },

        switchTo: function(CreatorType)
        {
            .....
        },

        reset: function()
        {
                .....
        },

        submit: function()
        {
            if (Status.submitting)
                return;

            if (!Creator.submit())
                return;

            var message    = CreatorMessage.hasClass('hint') ? '' : CreatorMessage.val();

            attachment = (CurrentCreator.getAttachment) ? CurrentCreator.getAttachment() : {};

            attachment.privacy  = Creator.Privacy.find('option:selected').val();
            attachment.target   = ActivityTarget;
            attachment.element  = ActivityType;
            attachment.filter   = ActivityList.find('#activity-type').val();

            Status.add(message, attachment);
        },

        add: function(message, attachment, callback)
        {
            ....
        }
    }
});

$(document).ready(function()
{
    joms.status.initialize({
        element: '.community-status',
        activityTarget: <?php echo $target; ?>,
        activityType: '<?php echo $type; ?>',
        activityList: '#activity-stream-container'

    });
});

})(joms.jQuery);

0 个答案:

没有答案