Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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
使用jquery获取span的值_Jquery_Html_Spring Boot_Thymeleaf - Fatal编程技术网

使用jquery获取span的值

使用jquery获取span的值,jquery,html,spring-boot,thymeleaf,Jquery,Html,Spring Boot,Thymeleaf,好的,我正在使用Spring boot开发一个web项目,并使用Thymeleaf作为模板引擎,在一个页面中,我有以下内容: [...]<span th:switch="${cost.achitat}" class="pull-right"> <span th:case='true' class="btn btn-xs btn-default" > <span class="g

好的,我正在使用Spring boot开发一个web项目,并使用Thymeleaf作为模板引擎,在一个页面中,我有以下内容:

[...]<span   th:switch="${cost.achitat}" class="pull-right">                                    
  <span th:case='true'  class="btn btn-xs btn-default" >
    <span class="glyphicon glyphicon-remove" aria-hidden="true" th:value="${cost.cost_id}"></span>
  </span> 
  <span th:case='false' class="btn btn-xs btn-default">
    <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
  </span> 
</span>[...]
但警报总是空的。我知道以前有人以某种形式问过这个问题,但我找不到解决办法,也不知道我做错了什么


谢谢

请注意,只有输入有值。其他必须使用数据属性

<span class="glyphicon glyphicon-remove" aria-hidden="true" th:attr="data-value=${cost.cost_id}"></span>

    $(document).ready(function(){
    $('.glyphicon.glyphicon-remove').click(function(){
        var t = $(this).data('value'); // if int the use parseInt() function;
        var t = paerseInt($(this).data('value'));
        alert(t);
    });});

$(文档).ready(函数(){
$('.glyphicon.glyphicon-remove')。单击(函数(){
var t=$(this.data('value');//如果int使用parseInt()函数;
var t=paerseInt($(this.data('value'));
警报(t);
});});

span
元素没有值。您可以使用
text()
获取他们的内部文本,或者使用
html()
获取他们的内部html。我不知道,谢谢!这里是你的要求链接。谢谢,工作几乎完美,只需一次修改
就无法添加数据值是的。这是因为您正在使用模板:)
<span class="glyphicon glyphicon-remove" aria-hidden="true" th:attr="data-value=${cost.cost_id}"></span>

    $(document).ready(function(){
    $('.glyphicon.glyphicon-remove').click(function(){
        var t = $(this).data('value'); // if int the use parseInt() function;
        var t = paerseInt($(this).data('value'));
        alert(t);
    });});