如何将此jquery代码附加到文档的末尾?

时间:2012-12-20 22:00:47

标签: jquery append

我需要将以下jquery附加到文档的底部..就在结束</body></html>标记之前..我该怎么做?

$(function(){
    $("#AttachmentFile").change(function(){
        $("#ufo-field-id-948").val($(this).val())
        var string = $("#ufo-field-id-948").val();
        var new_string = string.replace('C:\\fakepath\\', '');
        $("#ufo-field-id-948").val(new_string); 
    });
});

以下是需要添加的代码,然后附加在第一个附加

下面
        _createInput: function(){

        var self = this;



        var input = document.createElement("input");

        input.setAttribute('type', 'file');

        input.setAttribute('name', this._settings.name);

        input.setAttribute('id', 'AttachmentFile');
        if(this._settings.multiple) input.setAttribute('multiple', 'multiple');



        addStyles(input, {

            'position' : 'absolute',

            'right' : 0,

            'margin' : 0,

            'padding' : 0,

            'fontSize' : '480px',

            'fontFamily' : 'sans-serif',

            'cursor' : 'pointer'

        });



        var div = document.createElement("div");

        addStyles(div, {

            'display' : 'block',

            'position' : 'absolute',

            'overflow' : 'hidden',

            'margin' : 0,

            'padding' : 0,

            'opacity' : 0,

            'direction' : 'ltr',

            'zIndex': 2147483583

        });



        if ( div.style.opacity !== "0") {

            if (typeof(div.filters) == 'undefined'){

                throw new Error('Opacity not supported by the browser');

            }

            div.style.filter = "alpha(opacity=0)";

        }



        addEvent(input, 'change', function(){



            if ( ! input || input.value === ''){

                return;

            }



            var file = fileFromPath(input.value);



            if (false === self._settings.onChange.call(self, file, getExt(file))){

                self._clearInput();

                return;

            }



            if (self._settings.autoSubmit) {

                self.submit();

            }

        });



        addEvent(input, 'mouseover', function(){

            addClass(self._button, self._settings.hoverClass);

        });



        addEvent(input, 'mouseout', function(){

            removeClass(self._button, self._settings.hoverClass);

            removeClass(self._button, self._settings.focusClass);



            if (input.parentNode) {

                input.parentNode.style.visibility = 'hidden';

            }

        });



        addEvent(input, 'focus', function(){

            addClass(self._button, self._settings.focusClass);

        });



        addEvent(input, 'blur', function(){

            removeClass(self._button, self._settings.focusClass);

        });



    div.appendChild(input);

        document.body.appendChild(div);



        this._input = input;

    },

1 个答案:

答案 0 :(得分:0)

你必须用脚本标签包围它。然后把它放在你需要的地方。

<script type="text/javascript">
    $(function(){
        $("#AttachmentFile").change(function(){
            $("#ufo-field-id-948").val($(this).val())
            var string = $("#ufo-field-id-948").val();
            var new_string = string.replace('C:\\fakepath\\', '');
            $("#ufo-field-id-948").val(new_string); 
        });
    });
</script>