javascript - 如何在不点击的情况下运行这个脚本?

标签 javascript jquery html ajax json

This question is based on this question; but, there are some differences.


我的 friend 有一个在线网页,它有一个内联脚本标签,有一个JavaScript函数:

(#1):

var domain = window.location.protocol + "//" + window.location.host + '/';

$(document).ready(function() {
    var count = 5;
    countdown = setInterval(function() {
        if (count == 0) {
            $('#countdow').hide();
            $('#link-news').show()
        } else {
            $('#countdow').text(count);
            count--
        }
    }, 1700);
    $('#link-news').click(function() {
        var urls = $('input[name=linknexttop]').val();
        if (urls == 1) {
            $('input[name=linknexttop]').val(2);
            $.ajax({
                type: "GET",
                url: domain + "click.html",
                data: "code=Sh9QA&token=0982ff3066a3c60dbd3ecf9bcafc801b",
                contentType: "application/json; charset=utf-8",

                success: function(html) {
                    //alert(html);
                    window.location = html;
                }
            })
        }
    })
});

等待5秒后,会显示:

(#2):

 <div id="countdow">Please wait ...</div>
    <a href="javascript:(0)" onClick="return false" id="link-news" style="display:none;"><img src="en_tran.png" border="0" name="imgTag" /></a>
    </div>

现在,我想将数据发送到 click.html(在 #1 中),无需点击进入图像 imgTag(在 #2 中)。有可能用 JavaScript 实现吗?


Rule for playing: "I am allowed to insert my code bellow his original code only; so, I am not allowed to change anything in his code. And, the most important: code=Sh9QA&token=0982ff3066a3c60dbd3ecf9bcafc801b is random.".


最佳答案

您可以通过在5 秒倒计时。

或者直接在点击函数中调用ajax调用

    if (count == 0) {
        $('#countdow').hide();
        $('#link-news').show();
        $('#link-news').click(); /* This will trigger the click event without actually clicking on the image */
    } else {
        $('#countdow').text(count);
        count--
    }

关于javascript - 如何在不点击的情况下运行这个脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31956293/

相关文章:

javascript - 我可以用 JSON 做什么?

javascript - D3 的 Docuburst 式旭日图?

javascript - 结合不同变量的两个 if 语句

java - 如何将模型解析为 ajax post 调用

javascript - jQuery 移动 : Spacing the widgets in a page

html - CSS - 用 div 填充页面(水平)

HTML:元素的动态大小

javascript - 使用discord.js 在文本中提及名字

javascript - Chrome 以百分比正确显示自适应图像和宽度,Firefox 不正确

jquery - 通过 Jquery 更改伪属性?