在 PHP 中如何使用 jQuery 语法实现换行?

4

我希望找到在jQuery中的操作符,以便在PHP代码中内嵌jq代码时,将代码写在下一行。

这是我的工作代码:

        <?php
    $addoldgoldrow = '    
                                    $(document).on("click",".add_btns",function(e) {             
                                        e.preventDefault();
                                        var markups = "<tr class=\'rowaccs\'><td><input type=\'text\' class=\'sl_no\' name=\'sl_no[]\' style=\'width: 100%\'></td><td><input type=\'text\' class=\'oweight inputbox input_table1\' name=\'oweight[]\' style=\'width: 100%\'></td><td><input type=\'text\' class=\'ostone_weight  inputbox input_table1\' name=\'ostone_weight[]\' style=\'width: 100%\'></td><td><input type=\'text\' class=\'ovd inputbox input_table1\' name=\'ovd[]\' style=\'width: 100%\'></td><td><input type=\'text\' class=\'onet_weight inputbox input_table1\' name=\'onet_weight[]\'  style=\'width: 100%\'></td><td><input type=\'text\' class=\'orate inputbox input_table1\' name=\'orate[]\' value=\'' . $metal_rate . '\' style=\'width: 100%\'></td><td><input type=\'text\' class=\'oamount inputbox input_table1 table1_end row_end\' name=\'oamount[]\'  style=\'width: 100%\' readonly></td><td><span class=\'rowcloseoldgold\'><i class=\'fa fa-times\' style=\'color: #C11429;\' aria-hidden=\'true\'></i></span></td</tr>";
                                        $("table#old_gold tbody").append(markups);
                                        indexassigneroldpurchase(); 
                                    });       
                ';
    $this->registerJs($addoldgoldrow, View::POS_READY);
    ?>

我正在尝试做这样的事情

     <?php
    $addoldgoldrow = '    
                                    $(document).on("click",".add_btns",function(e) {             
                                        e.preventDefault();
                                        var markups = "<tr class=\'rowaccs\'>
                                                        <td><input type=\'text\' class=\'sl_no\' name=\'sl_no[]\' style=\'width: 100%\'></td>
                                                        <td><input type=\'text\' class=\'oweight inputbox input_table1\' name=\'oweight[]\' style=\'width: 100%\'></td>
                                                        <td><input type=\'text\' class=\'ostone_weight  inputbox input_table1\' name=\'ostone_weight[]\' style=\'width: 100%\'></td>
                                                        <td><input type=\'text\' class=\'ovd inputbox input_table1\' name=\'ovd[]\' style=\'width: 100%\'></td>
                                                        <td><input type=\'text\' class=\'onet_weight inputbox input_table1\' name=\'onet_weight[]\'  style=\'width: 100%\'></td>
                                                        <td><input type=\'text\' class=\'orate inputbox input_table1\' name=\'orate[]\' value=\'' . $metal_rate . '\' style=\'width: 100%\'></td>
                                                        <td><input type=\'text\' class=\'oamount inputbox input_table1 table1_end row_end\' name=\'oamount[]\'  style=\'width: 100%\' readonly></td>
                                                        td><span class=\'rowcloseoldgold\'><i class=\'fa fa-times\' style=\'color: #C11429;\' aria-hidden=\'true\'></i></span></td</tr>";
                                        $("table#old_gold tbody").append(markups);
                                        indexassigneroldpurchase(); 
                                    });       
                ';
    $this->registerJs($addoldgoldrow, View::POS_READY);
    ?>

加号运算符无法正常工作

我尝试使用“+”和“+'
哪个运算符最适合连接这些行?


我在第二次尝试中没有看到任何+ - 第二个片段的确切问题是什么? - Nico Haase
1
此外,我建议使用适当的模板语言 - 这正是它们被引入的确切原因:您会遇到引号、变量等问题,并且会失去概述。 - Nico Haase
1个回答

1

只需要在每行的末尾添加 \

这样你的代码就会像这样:

$addoldgoldrow = '    
  $(document).on("click",".add_btns",function(e) {             
    e.preventDefault();
    var markups = "<tr class=\'rowaccs\'> \
                    <td><input type=\'text\' class=\'sl_no\' name=\'sl_no[]\' style=\'width: 100%\'></td> \
                    <td><input type=\'text\' class=\'oweight inputbox input_table1\' name=\'oweight[]\' style=\'width: 100%\'></td> \
                    <td><input type=\'text\' class=\'ostone_weight  inputbox input_table1\' name=\'ostone_weight[]\' style=\'width: 100%\'></td> \
                    <td><input type=\'text\' class=\'ovd inputbox input_table1\' name=\'ovd[]\' style=\'width: 100%\'></td> \
                    <td><input type=\'text\' class=\'onet_weight inputbox input_table1\' name=\'onet_weight[]\'  style=\'width: 100%\'></td> \
                    <td><input type=\'text\' class=\'orate inputbox input_table1\' name=\'orate[]\' value=\'' . $metal_rate . '\' style=\'width: 100%\'></td> \
                    <td><input type=\'text\' class=\'oamount inputbox input_table1 table1_end row_end\' name=\'oamount[]\'  style=\'width: 100%\' readonly></td> \
                    td><span class=\'rowcloseoldgold\'><i class=\'fa fa-times\' style=\'color: #C11429;\' aria-hidden=\'true\'></i></span></td</tr>";
    $("table#old_gold tbody").append(markups);
    indexassigneroldpurchase();
});  ';     

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接