最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Automatically click a hyperlink in jqueryjs - Stack Overflow

programmeradmin2浏览0评论

I have a link where I need to be click it automatically using jquery or js.

If I click on the link the files are removing but I need to do it automatically after uploading all the files.

Actually I;musing plupload and it has functonality to remove all the files for jquery UI as $('#uploader').plupload('clearQueue'); but this is not working!

This is my link

<a id="deleteallfiles" href="#">[Remove all files]</a>

This my script:

 <script type="text/javascript">
    // Convert divs to queue widgets when the DOM is ready
    $(function () {
        $("#uploader").plupload({
            // General settings
            runtimes: 'gears,flash,silverlight,browserplus,html5',
            url: 'Final.aspx',
            max_file_size: '10mb',
            max_file_count: 25,
            chunk_size: '1mb',
            unique_names: true,

            // Resize images on clientside if we can
            //                    resize: { width: 320, height: 240, quality: 90 },

            // Specify what files to browse for
            filters: [
        { title: "Image files", extensions: "jpg,gif,png" },
        { title: "Zip files", extensions: "zip" }
    ],

            // Flash settings
            flash_swf_url: 'js/plupload.flash.swf',

            // Silverlight settings
            silverlight_xap_url: 'js/plupload.silverlight.xap'
        });


        // Client side form validation
        $('form').submit(function (e) {
            var uploader = $('#uploader').plupload('getUploader');

            // Files in queue upload them first
            if (uploader.files.length > 0) {
                // When all files are uploaded submit form
                uploader.bind('StateChanged', function () {
                    if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                        $('form')[0].submit();
                    }
                });

                uploader.start();
            }
            else
                alert('You must at least upload one file.');

            return false;
        });
        var uploader = $('#uploader').plupload('getUploader');
        uploader.bind('FileUploaded', function (up, file, res) {
            $('#showfilelist').append("<div id=" + file.id + " class='thumb'><a href='uploads/" + document.getElementById("currentDirectory").value + "/" + file.name + "' target='_blank' rel='gallery'><img src='uploads/" + document.getElementById("currentDirectory").value + "/" + file.name + "' width='50' height='50'/></a></div>");

          });

        //            $('#uploader').plupload('clearQueue');

        $('#deleteallfiles').click(function (e) {
            $.each(uploader.files, function (i, file) {
                uploader.splice(file);
            });
        });

      });

</script>

I have a link where I need to be click it automatically using jquery or js.

If I click on the link the files are removing but I need to do it automatically after uploading all the files.

Actually I;musing plupload and it has functonality to remove all the files for jquery UI as $('#uploader').plupload('clearQueue'); but this is not working!

This is my link

<a id="deleteallfiles" href="#">[Remove all files]</a>

This my script:

 <script type="text/javascript">
    // Convert divs to queue widgets when the DOM is ready
    $(function () {
        $("#uploader").plupload({
            // General settings
            runtimes: 'gears,flash,silverlight,browserplus,html5',
            url: 'Final.aspx',
            max_file_size: '10mb',
            max_file_count: 25,
            chunk_size: '1mb',
            unique_names: true,

            // Resize images on clientside if we can
            //                    resize: { width: 320, height: 240, quality: 90 },

            // Specify what files to browse for
            filters: [
        { title: "Image files", extensions: "jpg,gif,png" },
        { title: "Zip files", extensions: "zip" }
    ],

            // Flash settings
            flash_swf_url: 'js/plupload.flash.swf',

            // Silverlight settings
            silverlight_xap_url: 'js/plupload.silverlight.xap'
        });


        // Client side form validation
        $('form').submit(function (e) {
            var uploader = $('#uploader').plupload('getUploader');

            // Files in queue upload them first
            if (uploader.files.length > 0) {
                // When all files are uploaded submit form
                uploader.bind('StateChanged', function () {
                    if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                        $('form')[0].submit();
                    }
                });

                uploader.start();
            }
            else
                alert('You must at least upload one file.');

            return false;
        });
        var uploader = $('#uploader').plupload('getUploader');
        uploader.bind('FileUploaded', function (up, file, res) {
            $('#showfilelist').append("<div id=" + file.id + " class='thumb'><a href='uploads/" + document.getElementById("currentDirectory").value + "/" + file.name + "' target='_blank' rel='gallery'><img src='uploads/" + document.getElementById("currentDirectory").value + "/" + file.name + "' width='50' height='50'/></a></div>");

          });

        //            $('#uploader').plupload('clearQueue');

        $('#deleteallfiles').click(function (e) {
            $.each(uploader.files, function (i, file) {
                uploader.splice(file);
            });
        });

      });

</script>
Share Improve this question asked Nov 2, 2011 at 20:48 codercoder 13.2k32 gold badges115 silver badges219 bronze badges 4
  • You just use the click() function. – Sean Thoman Commented Nov 2, 2011 at 20:50
  • Yes I tried this way document.getElementById("deleteallfiles").click = document.getElementById("deleteallfiles").disabled = true; it but didn't work. – coder Commented Nov 2, 2011 at 20:50
  • Make sure you are using jquery to assign the event handler AND invoke the event, otherwise you may have issues. jQuery won't know about the handler if you use document.getElementById to assign... 'click' is just a property, remember. – Sean Thoman Commented Nov 2, 2011 at 20:59
  • Thanks for all your suggestions and may be something going wrong with my script I will look into it. – coder Commented Nov 2, 2011 at 21:06
Add a ment  | 

6 Answers 6

Reset to default 4
$('#someElement').trigger('click');

You just use the click function. ie

$('#someElement').click();

Do can just do:

$("a").click();

I think that could be the simpelst way to trigger the click event.

From the jquery documentation:

Its just a shorthand for the:

.trigger('click')

I think its as simple as this (tested in IE):

<script type='text/javascript'>
    function simulateClick() {
          var el = document.getElementById('deleteallfiles');
          el.click(); 
    }
</script>

Here is a reference from W3S: http://www.w3schools./jsref/dom_obj_all.asp

and here's another implementation with jQuery: http://api.jquery./click/

$("#deleteallfiles").trigger("click") Should work as you have a jquery click handler defined.

Simply utilize the click() event handler within jQuery:

Description: Bind an event handler to the "click" JavaScript event, or trigger that event on an element.

If no function() is specified then the event will be triggered by simply attaching the desired event to the desired element:

 $('#target').click();

This is actually a mon thing that I see people overlook way too much.

发布评论

评论列表(0)

  1. 暂无评论