I have script in aspx
page so I want that variable value in another JavaScript file.
function ValidateStartDate()
{
var txtDate = document.getElementById('<%=txtDateFilterActv.ClientID %>');
var lastdate = txtDate.value;
}
After click on save button I want 'lastdate
' variable value in another JavaScript file. How can I access it?
答案 0 :(得分:0)
txtDate.value is correct? you can easy test it with "alert(txtDate.value);" if it is correct you declare var lastdate outside the function (global) and then you can read in other javascript function. bye. example:
var lastdate;
function ValidateStartDate()
{
var txtDate = document.getElementById('<%=txtDateFilterActv.ClientID %>');
lastdate = txtDate.value;
}
答案 1 :(得分:0)
Say you have two files:
<script src="/test1.js"></script>
<script src="/test2.js"></script>
You could then change test1.js to:
var global = {};
global.settings = {
valid_start_date: ValidateStartDate
};
And then from test2.js you could use global like a scoped variable:
console.log(global.settings.valid_start_date);
答案 2 :(得分:0)
try this
var lastdate;
var ValidateStartDate = function(){
var txtDate = document.getElementById('<%=txtDateFilterActv.ClientID %>');
var lastdate = txtDate.value;
return lastdate;
}
lastdate = ValidateStartDate();
alert(lastdate);