문제

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');
  • You need to double quotes the name here.
  • Without quotes, you will get error like:
    • Syntax error, unrecognized expression: input[name=DateOfBirth[0]]

FIDDLE

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top