gpt4 book ai didi

Javascript:变量在分配时被 trim

转载 作者:行者123 更新时间:2023-12-03 08:35:47 28 4
gpt4 key购买 nike

我有一个从 AJAX 返回的变量 row['case'] ,它等于“Hello World!”。问题是,当我尝试将其分配给另一个变量时,只有“Hello”被分配,row['case'] =“Hello”,而不是row['case' ] =“ Hello World !”

这是出现问题的代码块:

$(document).ready(function() {
var table = $('#peacecard').DataTable({
"ajax": "http://localhost:8080/peace_reports/data.php",
"columns": [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
{ "data": "Name" },
{ "data": "Vendor", "className": 'dt-right' }
{ "data": "case", "render": function(data, type, row, meta){
if (data == "true"){
data = "<i title="+row['case2']+" id='thei'; }
else { data = ""; }
return data; },
"className": 'dt-center'}
],
"order": [[1, 'asc']]
});

这是 console.log(row) 显示的内容:

Object {Vendor: "123", Name: "MyHome", case2: "Hello World!"}

最佳答案

您缺少引号和 </i>在这一行:

data = "<i title="+row['case2']+" id='thei';

应该是这样的:

data = "<i title='"+row['case2']+"' id='thei'></i>";

关于Javascript:变量在分配时被 trim ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33223145/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com