ドロップダウンリストに特定の値が選択されている場合、カレンダーを入力フィールドに設定したい。私が直面している問題は、イベントが発生するが、クリックが複数回発生するまでスクリプトが実行されないことです。試しclick
てみfocus
ましたが、同じ結果になりました!
ここに私のコードがあります
<select name="selectKey" id="selectKey">
<option value="1" >mail no</option>
<option value="2" > mail type</option>
<option value="3" selected="selected"> mail date</option>
<option value="4" >title</option>
</select>
<input type="text" name="srchTxt" id="srchTxt" value="">
そしてここにjsがあります
$(document).ready(function() {
$('input[name=srchTxt]').bind('focus', function(event) {
// event.stopPropagation();
if ($("select[name='selectKey']").children(':selected').val() == 3) {
console.log('ysssssssssssssss');
$('input[name=srchTxt]').datepicker({
// showWeek: true,
firstDay: 1,
dateFormat: 'dd/mm/yy'
})
}
});
});
ここにデモがありますhttp://jsfiddle.net/VAvwG/