如何用javascript从html中提取信息

Kin*_*une 2 html javascript jquery hta

我有这组代码,它们将链接到hta页面的各个部分:

<ul>
    <li><strong>Windows 10</strong> comes with a new design and features.</li><br><br>
    <li><strong><a href="#" class="startLinks" id="Edge">Microsoft-Edge</a></strong> has been introduced as Microsoft's next generation web browser.</li><br><br>
    <li><strong><a href="#" class="startLinks" id="Skype">Microsoft Skype for Business</a></strong> is the Lync that you know . </li><br><br>
    <li><strong><a href="#" class="startLinks" id="FindPrinter">Printer list</a></strong> ........... </li><br><br>
    <li><strong><a href="#" class="startLinks" id="Email">Email Signature</a></strong> ........... </li>
</ul>
Run Code Online (Sandbox Code Playgroud)

我希望Microsoft边缘,Microsoft skype for business,打印机列表和电子邮件签名成为链接,并根据点击JavaScript将slider.gotoslide(x)在此处使用的链接:

    $('div.Welcome a').click(function(){
        var itemClicked = 'div.Welcome a';
        if (itemClicked.index() === 0){  //Microsoft Edge
            slider.goToSlide(6); //slide 6
        }
        else if (itemClicked.index() === 1) { //Microsoft Skype for Business
            slider.goToSlide(10); //slide 10
        }
        else if (itemClicked.index() === 2) { //Find and Add Printers
            slider.goToSlide(15); //slide 15
        }
        else if (itemClicked.index() === 3) { // Email Signature
            slider.goToSlide(11); //slide 11
        }
        return false;
    });
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我需要div.welcome a给我点击哪个链接然后if语句告诉我要去哪个幻灯片.然而索引就是这么说的

对象不支持属性或方法"索引"

Shy*_*yju 5

使用$(this).

使用上面的表达式,您将使用jQuery 转换/包装调用的元素(this)(在本例中为clicked anchor标记).所以这个表达式的结果将是一个jQuery对象.

$(function(){

   $('div.Welcome a').click(function(e){
       e.preventDefault();  //prevent default link click behaviour

       var itemClicked = $(this);

       var id = itemClicked.attr("id");  //get the Id of the clicked a tag

       alert(id);
      //use id for your further code now

   });

});
Run Code Online (Sandbox Code Playgroud)

是一个有效的jsBin示例.