duancha1065 2016-09-30 22:59
浏览 46

与php函数不兼容的javascript错误

I hava an error javascript. This javascript create a dynamic table add and remove.

In reality, the script is correct and work perfetly but, inside my tools I hava a function than create a problem with this javascript and I want know if it's possible to modify this javascript.

The problem come from this element who create a dropdown (HTML::selectMenu)

<td class='col-md-2'><?php echo HTML::selectMenu('suppliers_id[["+i+"]', $OSCOM_ProductsAdmin->SupplierDropDown()); ?>

I have this function than can't touch else this site does'nt work.

public static function output($string, $translate = null) {
  if (!isset($translate)) {
    $translate = ['"' => '&quot;'];
  }

      return strtr(trim($string), $translate);
    }

inside the the html HTML::selectMenu function (dropdown) I have inside

$field = '<select name="' . static::output($name) . '"';

When I edit my htmlpage generated this code become

<select name="suppliers_id[[&quot;+i+&quot;]" id="suppliers_id[[&quot;+i+&quot;]" class="form-control"><option value="">--Aucun--</option><option value="1">test</option></select>

and the problem come here : [&quot;+i+&quot;] and must be ['+i+'] (like the javascript)

How to resolve the problem ?

Thank you

  <script>
    $(document).ready(function(){
      var i=<?php echo $id-1; ?>;
      $("#add_row").click(function(){
        $('#addr'+i).html("<td>"+ (i+1) +"</td>" +

          "<td class='col-md-2'><input name='id["+i+"]' type='text' placeholder='Name' class='form-control'  /> </td><td class='col-md-2'><?php echo HTML::selectMenu('suppliers_id[["+i+"]', $OSCOM_ProductsAdmin->SupplierDropDown()); ?></td><td class='col-md-2'><input  name='discount_quantity["+i+"]' type='text' placeholder='Qty'  class='form-control'></td><td class='col-md-2'><input  name='discount_supplier_price["+i+"]' type='text' placeholder='Supplier Price'  class='form-control'></td><td class='col-md-2'><input  name='discount_customer["+i+"]' type='text' placeholder='Without %' class='form-control'></td>");


        $('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>');
        i++;
      });
      $("#delete_row").click(function(){
        if(i>1){
          $("#addr"+(i-1)).html('');
          i--;
        }
      });

    });
</script>
  • 写回答

2条回答 默认 最新

  • dongzhuang1923 2016-10-01 03:03
    关注

    I don't really understand why you need to even apply that output() method in the firstplace. All it's doing is adding the quote replacement that you don't want, so:

    1) Don't even apply that method:

    $field = '<select name="'.$name.'"';
    

    2) If that method is not the full method and it does more that you aren't showing or it's in a function/method at a higher level that you can't modify, then just convert the output using htmlspecialchars_decode($str,ENT_QUOTES):

    echo htmlspecialchars_decode(addslashes('<select name="suppliers_id[&quot;+i+&quot;]" id="suppliers_id[&quot;+i+&quot;]" class="form-control"><option value="">--Aucun--</option><option value="1">test</option></select>'), ENT_QUOTES);
    

    You may have to use addslashes() before hand, then decode.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大