开发者

Get value of hidden input field in JS

开发者 https://www.devze.com 2023-03-15 20:53 出处:网络
I need to get the value of a hidden input field using JS, var credoff = parseInt($(this).children(\'input.credoff:hidden\').val());

I need to get the value of a hidden input field using JS,

   var credoff = parseInt($(this).children('input.credoff:hidden').val());

which works fine in FF but does not work in IE, the input im talking of is the following...

<input type='hidden' value='$row->coff' class='credoff' name='cre开发者_StackOverflow中文版doff'/> 


Could you try input[type='hidden']?


Are there many other elements with the 'credoff' class?

There are comments in the jQuery documentation for the :hidden selector related to this.

http://api.jquery.com/hidden-selector/

Apparently in IE, the :hidden selector also selects elements, so it's possible that you're not getting back the right element. You could try

var credoff = parseInt($(this).children('input.credoff:hidden').not('option').val());


This might work:

var credoff = parseInt($(this).children('input[name="credoff"]').val());

Although I don't know what 'this' is. More code would be helpful.


Or this:

var credoff = parseInt($(':input[type:"hidden"][name:"credoff"]').val());


This must work:

var credoff = parseInt($(this).children('input[name="credoff"][type="hidden"]').val());

0

精彩评论

暂无评论...
验证码 换一张
取 消