我有一些 html 标记:
<div id="content">
<h3>blablalba</h3>
<p>paragraph1</p>
<p>paragraph2</p>
<p>paragraph3</p>
<h3>blablabla</h3>
<p>paragraph4</p>
<p>paragraph5</p>
<p>paragraph6</p>
</div>
还有一个突出显示所有标签的函数(重要的是:我需要突出显示所有标签)以及我需要知道它是否是一个段落的类。
function myClass (input) {
this.input = input;
//on init
init = function() {
alert(input); //Point to determine if it is a paragraph
};
init();
};
$(function() {
$("#content *").hover( function () {
$(this).css("border", "1px solid blue"); // style to mark (highlight) the tag
return false;
},
function () {
$(this).css("border", "none"); // unmark the tag
}).click( function () {
var inst = new myClass($(this).html());
});
});
如何查找我是否点击了该段落,而不是其他标签。
样本http://jsfiddle.net/rvvbf4L1/1/
提前致谢。
最佳答案
在点击处理程序中,您可以简单地使用 $(this).is('p')
来测试单击的元素是否是段落。
<强> jsFiddle example
关于javascript - 如何判断我是否点击了标签<p>中的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31633173/