Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery获取一个自定义(组合)属性值_Javascript_Jquery_Html - Fatal编程技术网

Javascript jquery获取一个自定义(组合)属性值

Javascript jquery获取一个自定义(组合)属性值,javascript,jquery,html,Javascript,Jquery,Html,我对以下html片段有一个简单的描述: <div onClick="javascript:getComments(this);" store-id="143568" class="CountryRow" style="padding: 4px;"><div class="flag flag_az"></div> &nbsp; Azerbaijan</div> 有人能告诉我我做错了什么吗。这非常有效: getComments = funct

我对以下html片段有一个简单的描述:

<div onClick="javascript:getComments(this);" store-id="143568" class="CountryRow" style="padding: 4px;"><div class="flag flag_az"></div> &nbsp; Azerbaijan</div>
有人能告诉我我做错了什么吗。

这非常有效:

getComments = function(input) {
  fValue =  $(input).attr("store-id");
  alert('the ID :'+fValue);
}
看看jQuery。就我个人而言,我会将HTML5用于jQuery中已经存在的此类情况

不管它值多少钱,考虑到参数,我相信您最初尝试执行的应该是这样的

getComments = function(input) {
   fValue =     $(input).html( $(input).attr("store-id") );
   alert('the ID :'+fValue.html());

   }

你所要做的就是:

fValue = $(input).attr("store-id");

您的代码片段正试图添加到div的“value”属性中(该属性不存在)

为了实现它的价值,HTML5为这样的自定义属性提供了一个标准工具。非常感谢。。我会在5分钟内接受你的回答(在stackoverflow允许我回答之后)@无论如何,谢谢你;)
fValue = $(input).attr("store-id");