3

I have a function that returns values from a database. My issue: the function adds "" on the return values. I need to trim the values before displaying them on the user's screen.

This is my function

 <script language="JavaScript" type="text/javascript">
    function handleProcedureChange(procedureid)
    {
        procedureid= document.form1.procedure.value;
        //alert(procedureid);
        var url ="some URL goes here"; 
        url=url+"ProcedureID="+procedureid;

        $.get(url, function(procedureResult) {
            $("#procedureDescription").text(procedureResult);
        });
    }
   </script>

The prcedureResult is the value being returned and the one I need to trim from the quotes before displaying it.

4

2 に答える 2

3

これを使用して引用符を削除します:

$.get(url, function(procedureResult) {
     procedureResult = procedureResult.replace(/^"+|"+$/g, "");
     $("#procedureDescription").text(procedureResult);
});

"これは、文字列の最初(^)と最後($)から何も("")に置き換えられます

于 2012-05-15T16:13:29.197 に答える
3

文字列値からすべての先頭と末尾の引用符を削除する次の関数を試してください

function stripQuotes(str) {
  str = str.replace(/^\"*/, '');
  str = str.replace(/\"*$/, '');
  return str;
}

そのまま使用できます

$.get(url, function(procedureResult) {
  procedureResult = stripQuotes(procedureResult);
  $("#procedureDescription").text(procedureResult);
});
于 2012-05-15T16:15:02.840 に答える