0

如何在 jquery 中引用类值、变量文本内容和变量属性?

使用以下带有以下变量的 jquery 代码:

var moveLeft = 10;
var log = [];
var strongContentText = $("#testList").text();
$("#aList").html("<input type='inputCheck' style='margin-left:"+moveLeft+"px"'>"</input>"<strong class='highLight'>"+strongContentText+"</strong><p>"+log.join(' ')+"</p>");

根据萤火虫,它说 SyntaxError: missing ) after argument list in this area moveLeft+"px"'>" 但我想不通

4

5 回答 5

0

试试这个:

$("#aList").html("<input type='inputCheck' style='margin-left:"+moveLeft+"px"'>"</input>"<strong class=\'highLight\'>"'+strongContentText+'"</strong><p>'+log.join(' ')+"</p>");

我调整了一些单引号和双引号问题。

于 2013-01-10T17:08:55.500 回答
0

试试这个:

$("#aList").html("<input type='inputCheck' style='margin-left:" + moveLeft + "px'></input><strong class='highLight '>" + strongContentText + "</strong><p>" + log.join(' ') + "</p>");
于 2013-01-10T17:08:57.463 回答
0

使用单引号来包含 html,以便在指定属性时可以使用双引号:

$('#aList').html('<input type="inputCheck" style="margin-left:'+moveLeft+'px"></input><strong class="highLight">'+strongContentText+'</strong><p>'+log.join(' ')+'</p>');

如果您更喜欢使用其中一个而不是另一个,则来回切换没有问题。这也有助于避免\在字符串中使用转义斜杠。

于 2013-01-10T17:08:58.830 回答
0

我想你只是有一些额外的报价在那里。

$("#aList").html("<input type='inputCheck' style='margin-left:"+moveLeft+"px'></input><strong class='highLight'>"+strongContentText+"</strong><p>"+log.join(' ')+"</p>");
于 2013-01-10T17:09:07.707 回答
0

现在试试:

$("#aList").html("<input type='inputCheck' style='margin-left:" + moveLeft + "px'></input><strong class='highLight'>" + strongContentText + "</strong><p>" + log.join(' ')+ "</p>");
于 2013-01-10T17:11:30.643 回答