0

I try to replace the type of a input through jquery from "date_calendar" to "date". The input's name is "DateOfBirth[0]", but for some reason it doesn't work with the code bellow..

I am new to jquery/javascript and maybe I am missing something.. How can I do it? What did I missed? This is the current code:

$(document).ready(function() {
$('input[name=DateOfBirth[0]]').attr('type', 'date');
});

HTML:

<input min="1938-04-28" max="1995-04-28" class="form_input_date" type="date_calendar" name="DateOfBirth[0]">

Thank you very much..

Edit: I tried the double backslash [name=DateOfBirth\\[0\\]] and to quote the name value [name="DateOfBirth[0]"] but it still doesn't work..

4

2 回答 2

1

只需这样做:

$('input[name="DateOfBirth[0]"]').attr('type', 'date');
  • 您需要在此处为​​名称加上双引号。
  • 如果没有引号,您将收到如下错误:
    • Syntax error, unrecognized expression: input[name=DateOfBirth[0]]

小提琴

于 2013-04-28T14:41:58.983 回答
1

您不能使用 jQuery 更改输入的类型属性,因为 IE 不支持它。

使用 jQuery 更改输入字段的类型

您需要销毁输入并创建一个新的。

于 2013-04-28T14:45:11.710 回答