我需要从以下位置获取id的编号:
<div class="social" th:data-url="@{http://localhost:8080/poll?id=${poll.pollId}" data-title="">但这是行不通的。我该怎么做呢?
发布于 2019-12-02 06:14:54
希望这能有所帮助。
$(document).ready(function(){
//get value of 'this' element that was clicked
var url = $(this).attr('data-url');
// split string and get value of id
var splitted = url.split("id=");
console.log("Id:"+splitted[1]);
});或绑定onclick或onchange事件
<div class="social" th:data-url="@{http://localhost:8080/poll?id=${poll.pollId}" th:onclick="'getId(\''+ ${poll.pollId} +'\')'" data-title="">并获取id值。
<script type="text/javascript">
function getId(id) {
console.log(id);
}
</script>发布于 2019-12-02 13:49:39
所有自定义属性都是使用th:attr属性定义的。像这样:
<div class="social" data-title=""
th:attr="data-url=@{|/poll?id=${poll.pollId}|}" data-title="">另外,使用URL或href指定@{}将构建完整的URL。
https://stackoverflow.com/questions/59128521
复制相似问题