无法获得<a> with Jquery

时间:2017-07-19 00:33:41

标签: javascript jquery variables

Good day guys, I have a problem, ive been trying get the value with jquery of an , below my code:

<li><a id="Prod1">12</a></li>

<script type="text/javascript"> 
function SendData(Parameter1,Parameter2){
var actual = $('#Prod1').val();
alert(actual); 
}
</script>

When I try to see the value it displays the following: [object Object] And I would like to see the number 12, which is the value inside the

Thanks for your time!

2 个答案:

答案 0 :(得分:3)

输入有值,在这里你试图获取节点的内容(或文本)

var actual = $('#Prod1').text();

或者您可以使用

var actual = $('#Prod1').html();

在上面的例子中,两个将是相同的,但如果你有任何标签,那么.html()会给你节点内容,即使用html标签

答案 1 :(得分:0)

我认为您可能正在寻找的是内部HTML而不是价值。

&#13;
&#13;
function SendData(Parameter1,Parameter2){
var actual = $('#Prod1').html();
alert(actual);
}

SendData();
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li><a id="Prod1">12</a></li>
&#13;
&#13;
&#13;