如何使用javascript从html中提取信息
我有这组代码,它们将链接到hta页面的各个部分:如何使用javascript从html中提取信息,javascript,jquery,html,hta,Javascript,Jquery,Html,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&l
<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>
正如您所见,我需要div.welcome a
来告诉我单击了哪个链接,然后是if语句来告诉我要转到哪个幻灯片。然而,指数是这样说的
对象不支持属性或方法“索引”
使用$(此)
使用上面的表达式,您正在转换/包装使用jQuery调用的元素(this
)(在本例中单击了锚定标记)。因此,这个表达式的结果将是一个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
});
});
是一个工作的jsBin示例。我觉得您需要更改的只是
var item='div.welcom a'到$('div.welcom a')代码>
?这是无效的html
和
不能包含除
Marc B以外的任何内容,那么正确的方法是什么?这似乎奏效了。我知道,即使它有效,也可能不正确,但如果你要说某件事是无效的,你最好解释一下如何正确操作,这样我就可以了解了。我已经告诉过你:
,不能包含除以外的任何内容。如果您想在列表中使用换行符,请将它们放在
中。这是行不通的,因为这不会给您单击的元素,它会给您所有与该选择器匹配的元素。是的,刚刚意识到它是一个类选择器。。。哎呀$(本)FTW
$(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
});
});