如何在数据库中包含引号的文本框中设置值?

我正在使用 Laravel 并且我有一个更新模式。我的数据没有设置在模态上,因为其中一个数据包含如下图所示的引号。 

http://img4.mukewang.com/61c56fb20001105d16070739.jpg

我的按钮代码是这样的:


<a type="button" data-toggle="modal" data-target="#cartitem_update_modal" class="dropdown-toggle btn btn-warning btn-circle" onclick="cartitem_update_modal('{{ $getdata->EQC_ID }}'

                                       , '{{ $getdata->EQC_ITEM_ID }}'

                                       , '{{ $getdata->EQC_ITEM_NAME }}'

                                       , '{{ $getdata->EQC_ITEM_QUANTITY }}'

                                       , '{{ $getdata->EQC_ITEM_UNIT }}'

                                       , '{{ $getdata->EQC_ITEM_REMARK }}')">

                                      <span class="fa fa-edit" aria-hidden="true"></span>

                                    </a>

我的 javascript 代码是这样的:


function cartitem_update_modal(EQC_ID, EQC_ITEM_ID, EQC_ITEM_NAME, EQC_ITEM_QUANTITY, EQC_ITEM_UNIT, EQC_ITEM_REMARK) 

{

    $('#cart_item_id_update').val(EQC_ID);

    $('#cart_item_update').val(EQC_ITEM_NAME);

    $('#cart_item_reserved_quantity_update').val(EQC_ITEM_QUANTITY);

    $('#cart_item_reserved_unit_update').val(EQC_ITEM_UNIT);

    $('#cart_item_remark_update').val(EQC_ITEM_REMARK);

}

我的问题是项目名称没有出现在我的文本框中<input type="text" class="form-control" id="cart_item_update" readonly>,这是因为数据有引号。我尝试选择不包含引号的数据,效果很好,数据显示在文本框中。


HUWWW
浏览 239回答 3
3回答

慕桂英4014372

由于您知道将在 javascript 调用中使用它,因此只需替换'by\'或将其替换为(space) 或什么都不做<a type="button" data-toggle="modal" data-target="#cartitem_update_modal" class="dropdown-toggle btn btn-warning btn-circle" onclick="cartitem_update_modal('{{ $getdata->EQC_ID }}'&nbsp; &nbsp; , '{{ $getdata->EQC_ITEM_ID }}'&nbsp; &nbsp; , '{{ str_replace("'", "\'", $getdata->EQC_ITEM_NAME) }}'&nbsp; &nbsp; , '{{ $getdata->EQC_ITEM_QUANTITY }}'&nbsp; &nbsp; , '{{ $getdata->EQC_ITEM_UNIT }}'&nbsp; &nbsp; , '{{ str_replace("'", "\'", $getdata->EQC_ITEM_REMARK) }}')">&nbsp; &nbsp; <span class="fa fa-edit" aria-hidden="true"></span></a>

12345678_0001

$('#cart_item_update').val(EQC_ITEM_NAME.replace(/\YOURQUOTATION_MARK/g,&nbsp;''));例如,要删除 £、€ 和 $ 的所有实例,您可以使用EQC_ITEM_NAME.replace(/£|\$|€|,|\./g,&nbsp;'')

至尊宝的传说

您正在寻找 htmlentities()<a type="button" data-toggle="modal" data-target="#cartitem_update_modal" class="dropdown-toggle btn btn-warning btn-circle"&nbsp;&nbsp; &nbsp;onclick="cartitem_update_modal('{{ $getdata->EQC_ID }}'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , '{{ $getdata->EQC_ITEM_ID }}'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , '{{ htmlentities($getdata->EQC_ITEM_NAME) }}'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , '{{ $getdata->EQC_ITEM_QUANTITY }}'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , '{{ $getdata->EQC_ITEM_UNIT }}'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; , '{{ $getdata->EQC_ITEM_REMARK }}')">&nbsp;&nbsp; &nbsp; <span class="fa fa-edit" aria-hidden="true"></span></a>
打开App,查看更多内容
随时随地看视频慕课网APP