由于我的项目有点超载javascript
&jQuery
脚本,我在尝试将其全部分成部分时遇到问题,......比如分类或阶段......
所以在这两个调用之前,它们是“当前项目”调用,
<head>
//i am loading the jQuery & jQuery-UI... and then :
// right after jQuery comes my first section of project
<script type="text/javascript" src="jsV2\jQueryAjaxNoPostBack.js"></script>
<script type="text/javascript" src="jsV2\stage1.js" ></script>
<script type="text/javascript">
// is valid in stage1.js , naturally...
var jsTxtVal = document.getElementById("TBX_TableSelectorFirstStage");
//and that won't work
var jQueryTxtVal= $('#TBX_TableSelectorFirstStage').val();
</script>
</head>
在那个单独的文件中我尝试
//stage1.js
//---- before ready()-------
//won't work
var jQueryTxtVal= $('#TBX_TableSelectorFirstStage').val();
//works
var jsTxtVal = document.getElementById("TBX_TableSelectorFirstStage");
$('document').ready(function () {
var TBX_TableSel = $('#TBX_TableSelectorFirstStage');
var jQueryTxtVal= $('#TBX_TableSelectorFirstStage').val();
var jsTxtVal = document.getElementById("TBX_TableSelectorFirstStage");
$('.someElement's Class).click(function () {
// this will not work unless i will assign "jQueryTxtVal" right here .
alert(jQueryTxtVal);
//and... this will work no matter where the assignment took place .
//either in main page (i call it "the globlas" of project)
//or at the top of every "section" of project...
alert(jsTxtVal );
});
现在如果我使用 plain JavaScript
,我什至可以为所有方法放置一段全局变量......几乎在任何地方,比如在<sctipt></srctipt>
jquery下,在主页.aspx
所以我想知道,我如何在 jQuery 中使用“全局变量”? 或者它只是那个用例(?)..我不这么认为......
...我也尝试过defer="defer"
通话stage1.js
,在 head-main 页面内.aspx
我没有尝试成功