2012-10-16 55 views
1

我試圖將下面的文字「這裏是一條評論」設置爲使用javascript的隱藏字段的值。但它會呈現以下輸出。使用javascript設置帶有特殊字符的隱藏字段值

<input type="hidden" comment"'="" a="" s="" value="1051_"Here" name="comment"> 

我需要在表單提交中獲取MVC控制器操作中的上述文本。如何使用JavaScript將特殊字符的上述文本設置爲隱藏字段的值,以便在使用特殊字符發送時可以捕捉到值。

回答

0

您的輸入代碼已經錯過了位置quotedouble quote

<input type="hidden" comment="" a="" s="" value="1051_Here" name="comment"> 

設定值

$("input[name='comment']").val("Here's a comment"); 
0

只是逃生單引號'用反斜槓\這樣的:

<input type="hidden" id="comment" name="comment" value=""> 

$('#comment').val('Here\'s a comment'); 

這裏有一個的jsfiddle測試:http://jsfiddle.net/leniel/vK2a9/