使用jquery获取span的值
好的,我正在使用Spring boot开发一个web项目,并使用Thymeleaf作为模板引擎,在一个页面中,我有以下内容:使用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
[...]<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);
});});