1
<div id="div1" value="3" onclick="Function(this.id,this.value)"></div>

this.id有效,但不是第二个论点。一直在谷歌搜索,但没有运气,所以我开始了自己的线程,希望你能帮忙!

注意:我不想发送里面的内容div,我想发送第二个属性(Value="3")。

4

4 回答 4

1

你有没有尝试以下方法:

theElement.getAttribute("Value");
于 2012-11-18T19:32:58.660 回答
1

你用jquery吗?试试这个$('#div1').attr('Value')$('#div1').val()

于 2012-11-18T19:35:38.933 回答
0

您的问题不是很清楚,但通常您可以检索如下属性:

element.getAttribute("Value");
于 2012-11-18T19:33:31.877 回答
0

It seems you're confusing property with attribute. Some standard attributes are available as properties, but nonstandard ones are generally not.

By the way, it's better (valid and more future-proof) to use data- prefixed attributes instead of nonstandard nonprefixed attributes for storing arbitrary data.

Your example can be correctly rewrited following way:

<div id="div1" data-value="3" onclick="Function(this.id,this.getAttribute('data-value')"></div>
于 2012-11-18T19:54:33.347 回答