Simply do this:
$('input[name="DateOfBirth[0]"]').attr('type', 'date');
- You need to double quotes the name here.
- Without quotes, you will get error like:
Syntax error, unrecognized expression: input[name=DateOfBirth[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..
解决方案
Simply do this:
$('input[name="DateOfBirth[0]"]').attr('type', 'date');
Syntax error, unrecognized expression: input[name=DateOfBirth[0]]
其他提示
You can't change the type property of an input using jQuery, because IE doesn't support it.
change type of input field with jQuery
You need to destroy the input and make a new one instead.