[英]Getting a complete string from server, when assigned to variable in JS it is not complete
so I sent a response from my backend to my JS.所以我从后端向我的 JS 发送了一个响应。 Server responded with服务器回应
{id: 347, name: "Dummy One", date: "July 14, 2020", status: "APPROVED"} {id:347,名称:“Dummy One”,日期:“2020 年 7 月 14 日”,状态:“已批准”}
When using val.name
to a table, it displays the complete value but when I assigned it to a variable, I am only getting the "Dummy"
value.将val.name
用于表时,它会显示完整的值,但是当我将其分配给变量时,我只会得到"Dummy"
值。
Here's my JS:这是我的 JS:
btns = "<td><button class='btn' data-name="+val.name+"</button></td>";
$('.btn').click(function(){
var name = $(this).attr('data-name');
console.log(name);
});
In your button HTML, you are missing >
after the data-name
attribute在您的按钮 HTML 中,您在data-name
属性之后缺少>
As @adiga mentioned in his comment try to change the button HTML according to the comment.正如@adiga 在他的评论中提到的,尝试根据评论更改按钮 HTML。
After that, you are assigning the data-name
attribute value to the name
variable之后,您将data-name
属性值分配给name
变量
try to change it with var name = $(this).data('name');
尝试用var name = $(this).data('name');
来改变它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.