2015-12-03 69 views
0

如何在您點擊第一個下拉菜單時啓用日期選擇器,其他下拉菜單和日期選擇器將出現選擇?如何啓用日期選擇器?

Javscript

function checkOption(obj) { 
     var CustomerBranch = document.getElementById("CustomerBranch"); 
     CustomerBranch.disabled = obj.value == "Please select"; 

     var monthyrtxt = document.getElementById("monthyrtxt"); 
     monthyrtxt.disabled = obj.value == ""; 

     <%--var fromdate = document.getElementById("fromdate"); 
     fromdate.datepicker("getDate") == "";--%> 
     <%--$(".fromdate").datepicker("enabled");--%> 
     <%-- $("#fromdate:enabled").datepicker(); --%> 
     var fromdate =document.getElementById("fromdate").disabled=''; 
     <%-- $("#fromdate:enabled").datepicker(); --%>  


     var todate = document.getElementById("todate"); 
     todate.disabled = obj.value == ""; 
    } 

HTML代碼

<td> 
Business Id :- 
</td> 

<td> <select name="Business" id="Business" onChange="checkOption(this)"> 
<option value="" disabled="disabled" selected="selected">-- Please select --</option> 
<%for(Business business : Businesslevel) {%> 
<option value="<%=business.getBusinessId()%>"><%=business.getBusinessId()%> - <%=business.getBusinessName()%></option> 
<%}%> 
</select> 
</td> 
</tr> 
<td> 
Branch Id : 
</td> 
<td> 
<select name="CustomerBranch" id="CustomerBranch" disabled="disabled"> 
<option value="" disabled="disabled" selected="selected">-- Please select --</option> 
<%for(CustomerBranch custBranch : CustBranch) {%> 
<option value="<%=custBranch.getBranchId()%>"><%=custBranch.getBranchName()%></option> 
<%} 
%> 
</select> 
</td> 
</tr> 
<tr> 
<td> 
From Date : 
</td> 
<td> 
<input type="text" id="fromdate" disabled="disabled"> 
</td> 
</tr> 
<tr> 
<td> 
To Date : 
</td> 
<td> 
<input type="text" id="todate" disabled="disabled"> 
</td> 
</tr> 

我已經嘗試了很多次,但它仍然沒有奏效。非常感謝你的幫助。 enter image description here

+0

你介意編輯第一句話。很難遵循你想要達到的目標。 –

+0

函數checkOption(obj){var CustomerBranch = document.getElementById(「CustomerBranch」); CustomerBranch.disabled = obj.value ==「請選擇」; var monthyrtxt = document.getElementById(「monthyrtxt」); monthyrtxt.disabled = obj.value ==「」; var fromdate = document.getElementById(「fromdate」); fromdate .disabled = obj.value ==「」; var todate = document.getElementById(「todate」); todate.disabled = obj.value ==「」; } – Maihani

+0

當我們已經選擇第一個下拉列表時,啓用日期選擇器的正確功能是什麼? – Maihani

回答

0

而不是使用純JavaScript使用jQuery。它易於啓動的庫。只需添加<link rel="stylesheet" href="/resources/demos/style.css">

<head>

<!doctype html> 
 
<html lang="en"> 
 
<head> 
 
    <meta charset="utf-8"> 
 
    <title>jQuery UI Datepicker - Default functionality</title> 
 
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
 
    <script src="//code.jquery.com/jquery-1.10.2.js"></script> 
 
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
 
    <link rel="stylesheet" href="/resources/demos/style.css"> 
 
    <script> 
 
    $(function() { 
 
    $("#fromDate").datepicker(); 
 

 
    $("#toDate").datepicker(); 
 

 
    }); 
 
    </script> 
 
</head> 
 
<body> 
 
    
 
<p>From Date: <input type="text" id="fromDate"></p> 
 
    
 

 
<p>To Date: <input type="text" id="toDate"></p> 
 
    
 

 
    
 
</body> 
 
</html>

+0

謝謝@Zumry穆罕默德爲您解答。但我不是那樣的頁面。當我們打開頁面時,我想要它,其他下拉列表,日期選擇器或文本框被禁用。當我已經從第一個下拉列表中選擇時,日期選擇器將會出現......我已經嘗試了很多次,但仍然無法工作。 – Maihani

相關問題