[英]append values with both single and double quotes to textbox
這是因為你連接字符串,不考慮轉義特殊字符。 您應該使用.val
設置值,以便正確轉義該值。 此外,正則表達式是不必要的。
$(document).ready(function(){
var test= "this is vicky\"s \"s 's 's \"s \"S";
alert(test);
var input = $("<input style='width:700px;' id='testbox'></input>").val(test);
$("#test").html("hey this is ").append(input);
});
所以為了解決這個問題而不使用.find
或單獨附加var
,我找到了一個簡單的解決方案。 我只需要用它的iso latin代碼替換single quote
“ ' ” '
和其他特殊字符及其各自的代碼,然后在.html
使用該變量
var something= "this is vicky\"s \"s 's 's \"s \"S";
test=something.replace(/'/g,"'").replace(/"/g,'\\"');
$("#test").html("hey this is <input id='testbox' value='"+test+"'></input>");
我嘗試了很多事情,最后這奏效了:
var getClinician = row.ClinicianName;
getClinician = getClinician.replace(/"/g, """);
var Clinician = '<td align=""><input type="text" id="txt_Clinician_' + row.ScheduleID + '" value="' + getClinician + '" />';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.