JavaScript中的锚标记ID探针 [英] Anchor tag id probelm in javascript
本文介绍了JavaScript中的锚标记ID探针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要定位标记的ID值.它不起作用.该值未定义.
这是我的代码:
HTML代码:
I need id value of the anchor tag.It is not working.The value is coming undefined.
This my code:
HTML Code:
<a href="#" önclick="return listname1(this)" id="hollywood">A</a>
javascript代码:
javascript code:
function listname1(list){
//alert(list.text);
var abc=list.text;
alert(abc);
var category=document.getElementById('hollywood').value;
alert(category);
// window.location="hollywood1.php?type="+abc;
}
推荐答案
标签具有innerHTML属性以获取其文本,请尝试如下操作:
a tag has innerHTML property to get its text, try like this:
function listname1(list) {
//alert(list.text);
var abc = list.innerHTML;
alert(abc);
var category = document.getElementById('hollywood').innerHTML;
alert(category);
// window.location="hollywood1.php?type="+abc;
}
正在运行,您可以参考并使用:
This is working you can refer this and use:
function listname1(sender)
{
alert(sender.innerText);
}
<a href="#" onclick="return listname1(this)" id="hollywood">A</a>
P.S.希望我能正确理解问题,如果不解决,请告诉我.
P.S. I hope i understood the problem correctly and the solution works for you if not do let me know.
使用
var category=
这篇关于JavaScript中的锚标记ID探针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文