日期:2014-05-16  浏览次数:21105 次

js 代码 用.find找元素, 然后模拟点击, 为啥不行呢
用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>

------解决方案--------------------
$("#btn_3").find(".btn_single_go").click();

.click()
只是调用 当前dom绑定的click事件
但是并不会帮你点 a链接

------解决方案--------------------
模拟点击没起作用!
onclick="javascript:window.location.href='http://www.163.com';"
你要加个onclick事件才行。
因为click是执行的事件不是href属性。
------解决方案--------------------
不多说,贴源码,不懂找我

<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>