js 代码 用.find找元素, 然后模拟点击, 为啥不行呢

laihongbo524 2013-11-04 03:19:32
用JS代码去模拟点击

就这一段, 模拟点 第163的那个链接, 没反应
$("#btn_3").find(".btn_single_go").click();

如果用我$("#btn_3").html("将里面的内容修改, 可以成功修改的")


下面是 网页的示例代码
<html>
<body style="">
<div class="viewport">
<div id="open_button">

<div class="row poster_button">
<div class="h_box">
<div id="btn_1" class="h_flex">
<a href="http://www.hao123.com/" class="btn_buy">hao123</a>
</div>
</div>
</div>

<div class="row poster_button" id="extra_open_button">
<div class="h_box">
<div id="btn_3" class="h_flex">
<a href="http://www.163.com" class="btn_single_go">163</a>
</div>
</div>
</div>

</div>
</div>
</body>
</html>
...全文
1690 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
未知数 2013-11-11
  • 打赏
  • 举报
回复
目测没问题, 代码应该可以成功, 不行的话你可以试试 $("#btn_3").find(".btn_single_go")[0].click(); 实在不行就写click事件 $("#btn_3").find(".btn_single_go").click(function(){ window.location.href = $(this).attr("href"); return false; }); $("#btn_3").find(".btn_single_go").triggerHandler('click');
辛格瑞拉 2013-11-11
  • 打赏
  • 举报
回复
不多说,贴源码,不懂找我

<script type="text/javascript">

    $(document).ready(function(){

        $("#btn_submit").click(function(){		
		
           $("#btn_3").find(".btn_single_go").trigger('click');

        });
		 $(".btn_single_go").click(function(){
			window.location.href = $(this).attr("href");		

        });
		
    });
</script>
laihongbo524 2013-11-04
  • 打赏
  • 举报
回复
例如这段代码, 是网页上的JS, 点击后的操作 我就是要找个用JS的方法去点击他 $("#open_button").find(".btn_buy_go").on("click", function() { a.mode[$(this).attr("data-type")] = !0; var b = a.config.mode = $ (this).attr("data-type"); if ($.cookie("userId"))a.getData(!0, function() { $(a.modeModals[b]).css("display", "block"), $(a.modeModals[b]) .find(".close").on("click", function() { $(a.modeModals[b]).css("display", "none"), window.clearTimeout(a.timer), a.timer = null } ), a.toProcess(b) } ); else { if (WebEventTrigger("login", null))return ; window.location.href = "http://www.xxx.com/index.php/v1/authorize/sso?client_id=180100031013&callback=" + encodeURIComponent(window.location.href) } }
laihongbo524 2013-11-04
  • 打赏
  • 举报
回复
那有什么办法 可以用JS模拟点击到上面, 网页上的内容是不能修改的(不是自已的)
keatkeat1987 2013-11-04
  • 打赏
  • 举报
回复
<a href="http://www.163.com" class="btn_single_go">163</a> 不是事件 。 要绑定事件先
Null_Reference 2013-11-04
  • 打赏
  • 举报
回复
模拟点击没起作用! onclick="javascript:window.location.href='http://www.163.com';" 你要加个onclick事件才行。 因为click是执行的事件不是href属性。
KK3K2005 2013-11-04
  • 打赏
  • 举报
回复
$("#btn_3").find(".btn_single_go").click(); .click() 只是调用 当前dom绑定的click事件 但是并不会帮你点 a链接

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧