Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.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可以';t获取数据-*属性值,返回未定义_Javascript_Php_Jquery_Html_Twig - Fatal编程技术网

Javascript jQuery可以';t获取数据-*属性值,返回未定义

Javascript jQuery可以';t获取数据-*属性值,返回未定义,javascript,php,jquery,html,twig,Javascript,Php,Jquery,Html,Twig,Sup,我在使用jQuery获取数据-*值时遇到问题 我的HTML代码是: <button type="button" class="btn btn-danger" id="{{ currency.id }}" data-curname="{{ currency.name }}" data-toggle="modal" data-target="#deleteConfirm" onclick="deleteCurConf(this.id)">

Sup,我在使用jQuery获取数据-*值时遇到问题

我的HTML代码是:

<button type="button" 
   class="btn btn-danger"
   id="{{ currency.id }}"
   data-curname="{{ currency.name }}"
   data-toggle="modal"
   data-target="#deleteConfirm"
   onclick="deleteCurConf(this.id)">
   <span class="glyphicon glyphicon-remove"></span>
   &nbsp;Delete
 </button>
但是控制台日志返回未定义的。最有趣的是,这段代码昨天还在运行,但今天它被破坏了。 有什么想法吗


顺便说一句,我正在使用Bootstrap3和Twig,需要做两个小改动:

1) 调用函数时只需传递
this
而不是
this.id

<button type="button" 
   class="btn btn-danger"
   id="{{ currency.id }}"
   data-curname="{{ currency.name }}"
   data-toggle="modal"
   data-target="#deleteConfirm"
   onclick="deleteCurConf(this)">
   <span class="glyphicon glyphicon-remove"></span>
   &nbsp;Delete
</button>
function deleteCurConf(id) {
 var curName = $(id).data('curname'); // use $(id)
 console.log(curName);
}

需要做两个小改动:

1) 调用函数时只需传递
this
而不是
this.id

<button type="button" 
   class="btn btn-danger"
   id="{{ currency.id }}"
   data-curname="{{ currency.name }}"
   data-toggle="modal"
   data-target="#deleteConfirm"
   onclick="deleteCurConf(this)">
   <span class="glyphicon glyphicon-remove"></span>
   &nbsp;Delete
</button>
function deleteCurConf(id) {
 var curName = $(id).data('curname'); // use $(id)
 console.log(curName);
}

在jQuery中更干净的方法是:

   <button type="button" 
   class="btn btn-danger handleClick"  // Added extra class
   id="{{ currency.id }}"
   data-curname="{{ currency.name }}"
   data-toggle="modal"
   data-target="#deleteConfirm"       
   <span class="glyphicon glyphicon-remove"></span>
   &nbsp;Delete
 </button>

在jQuery中更干净的方法是:

   <button type="button" 
   class="btn btn-danger handleClick"  // Added extra class
   id="{{ currency.id }}"
   data-curname="{{ currency.name }}"
   data-toggle="modal"
   data-target="#deleteConfirm"       
   <span class="glyphicon glyphicon-remove"></span>
   &nbsp;Delete
 </button>
最后它成功了:)非常感谢:)也许你知道为什么这个代码昨天有效,尽管有一个错误?好的,没关系:)非常感谢你的帮助,很抱歉我没有足够的排名来投票支持你的答案,所以这里为你加1:)最后它成功了:)非常感谢:)也许你知道为什么这个代码昨天有效,虽然有一个错误?好的,没关系:)非常感谢你的帮助,很抱歉我没有足够的排名来投票支持你的答案,所以这里给你+1:)