【问题标题】:Pass 2 values into 2 attributes in jQuery将 2 个值传递给 jQuery 中的 2 个属性
【发布时间】:2019-04-08 14:06:52
【问题描述】:

我对 Node.js 和 Pug 引擎模板有疑问。 在 PHP(HTML) 中,我可以轻松地将两个值传递给 2 个属性: 例如(我将 row[id] 传递给按钮的 idclass 属性):

 <?php  
 while($row = mysqli_fetch_array($result)) {  
 ?>  
 <tr>  
 <td><?php echo $row["name"]; ?></td>  
 <td><input type="button" name="view" value="View" id="<?php echo 
 $row["id"]; ?>" class="<?php echo $row["id"]; ?>" /></td>
 </tr>  
 <?php  
 }  
 ?>  

如何将 row.id 传递到 Node.js(Pug )?在下面的示例中,Pug 没有定义“类”属性。 Example

$.ajax({
                    type: "POST",
                    //contentType: "application/json",
                    url: "select_marks",
                    //data: formData,   //JSON.stringify(formData),
                    dataType: 'json',
                    success: function (data) {
                        $.each(data, function (i, row) {
                            $('.content').append(
                                 "<input type ='button' id=" + row.id + "class=" + row.id + ">"
                            );

                        });
                    }
                });

【问题讨论】:

标签: jquery node.js pug


【解决方案1】:

它的引号问题不要忘记你的 html 属性中有''

如果你的行中有好的数据,我就这样写

$('.content').append(
   "<input type ='button' id='" + row.id + "'class='" + row.id + "'/>"
);

https://jsfiddle.net/j0z5Lxc4/3/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-23
    • 2016-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多