JQuery Auto点击<a> Tag is not working

时间:2017-11-25 14:06:50

标签: javascript jquery click jquery-click-event

I have the anchor in the HTML page and I want to click on the below anchor only once when the page is loaded but it's not clicking on the anchor element.

HTML

<a aria-label="Options" class="_5vmb button _p" data-ft="{&quot;tn&quot;:&quot;p&quot;}" data-hover="tooltip" data-tooltip-content="Options" data-tooltip-position="below" href="#" role="button" id="js_28" aria-controls="js_9y"></a>

I had tried the JQuery as below but it not working

$(document).ready(function () {
    $('._5vmb button _p').trigger('click');
});

3 个答案:

答案 0 :(得分:4)

选择器错误:

$(document).ready(function() {
  $('._5vmb.button._p').trigger('click');
});

应该是:

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<a aria-label="Options" class="_5vmb button _p" data-ft="{&quot;tn&quot;:&quot;p&quot;}" data-hover="tooltip" data-tooltip-content="Options" data-tooltip-position="below" href="#" role="button" id="js_28" aria-controls="js_9y">a tag</a>
&#13;
  material = new THREE.MeshPhongMaterial({
    color: 0xFF9800, 
    side: THREE.BackSide,
    opacity: 1//0
  });
&#13;
&#13;
&#13;

答案 1 :(得分:1)

尝试点击事件功能

以下是click function

的文档

&#13;
&#13;
 $(document).ready(function() {
  $('._5vmb.button._p').on('click', function(){console.log('clicked')});
    $('._5vmb.button._p').click();
   });
   
   
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a aria-label="Options" class="_5vmb button _p" data-ft="{&quot;tn&quot;:&quot;p&quot;}" data-hover="tooltip" data-tooltip-content="Options" data-tooltip-position="below" href="#" role="button" id="js_28" aria-controls="js_9y"></a>
&#13;
&#13;
&#13;

答案 2 :(得分:1)

不应该

 $(document).ready(function() {
    $('._5vmb.button._p').trigger('click');
   });

如果我正确阅读你的HTML