最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

how to remove single quote from the value of hidden field in javascript - Stack Overflow

programmeradmin3浏览0评论

I am reading hidden field value using javascript. The value I am getting is within single quote( '78963' ). I can i remove this single quote ? I want the value without single quote( 78963 ). Please help me to solve the problem.

I am reading hidden field value using javascript. The value I am getting is within single quote( '78963' ). I can i remove this single quote ? I want the value without single quote( 78963 ). Please help me to solve the problem.

Share asked Mar 20, 2013 at 10:01 IrannabiIrannabi 1391 gold badge4 silver badges15 bronze badges 1
  • 1 Do you mean simply this: yourValue.replace(/'/g, "");? Or am I missing something? What are the possible values of the string? – James Allardice Commented Mar 20, 2013 at 10:03
Add a ment  | 

5 Answers 5

Reset to default 5

I guess you simply want to convert your string value to numeric.

Just use parseInt():

parseInt("78963", 10);  // 78963

If the value pretends to be floating, there is parseFloat() method:

parseFloat("78963.1");  // 78963.1

And one more shortcut to make casting:

+"78963";  // 78963

In case if you simply want to replace single quotes, you may use:

"'78963'".replace(/'/g, "");  // "78963"

(as stated by others) or do tricky split:

"'78963'".split("'")[1];  // "78963"

You can use .replace() function on strings: http://www.w3schools./jsref/jsref_replace.asp

str.substr(1, str.length - 2);

Just $('#element').val(), you will get exact value. here element will be the id of hidden box.

If it's true that the value of the hidden input field contains single quotes, the (in my opinion) best answer is the one which JamesAllardice put in a ment:

yourValue.replace(/'/g, "");
发布评论

评论列表(0)

  1. 暂无评论