jQuery - 如何按ID包含字符选择元素?

时间:2015-01-22 04:15:33

标签: jquery wordpress

我在WordPress网站上使用以下表单:

<input id="abc_settings[update_date]" name= "abc_settings[update_date]" 
type="checkbox" value="1" <?php checked('1', $abc_options['update_date']); ?>/>

如果我将ID更改为&#34;更新&#34;,我可以使用

选择它
value = $('#update').val();

但是,我无法弄清楚如何获得abc_settings[update_date]的价值。 这个不起作用:

value = $('abc_settings[update_date]').val();

我保留名称abc_settings,以便我可以在WordPress中使用global $abc_settingsglobal $abc_options

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

尝试逃避[]这样的字符:

value = $('#abc_settings\\[update_date\\]').val();

我不完全确定这是否会奏效,但我的理由是:

http://learn.jquery.com/using-jquery-core/faq/how-do-i-select-an-element-by-an-id-that-has-characters-used-in-css-notation/

相关问题