2014-02-11 63 views
0

我有一個web應用程序,每發送一個輸入到input=hidden 之後,我發送隱藏value到服務器。JQuery替換隱藏值雙引號

的事情是,我需要它去hidden input像之前轉義引號:

$('.textBoxSal').live('keyup', function() { 
//...code... 
     $('.' + cell + 'Td').html(myValue.replace('"', "&quot;") + '<input type="hidden" class="' + cell + 'Out" value="' + myValue.replace('"', "&quot;") + '"/>'); 

我不知道爲什麼,但它拒絕使其在隱藏輸入發生.. 我甚至在那裏放置了一個console.log,代碼似乎在console.log

中工作可能是什麼問題?

編輯:這裏有一個例子 http://jsfiddle.net/DSZm4/

+0

首先你的選擇是(有效)'」 .classNameTD''(你需要一個(選擇這個類名的'td'後裔,或者'td' *有*那個類名?);並且'live()'在jQuery 1.7+和* removed中被棄用*(如果沒有你的HTML,*和*最好是一個[JS Fiddle] (http://jsfiddle.net/) ,很難提供具體的幫助。 –

+0

@DavidThomas你去了嗎:http://jsfiddle.net/DSZm4/ – thormayer

回答

1

你需要使用一個全球性的正則表達式是:

myValue.replace(/"/g, '\\"'); 
+0

你可以請添加幾句關於你的解決方案?它似乎不工作,但也許如果我會明白你爲什麼說它.. – thormayer

+0

你可以爲你的問題創建小提琴嗎? –

+0

你去了... http://jsfiddle.net/DSZm4/ – thormayer