从Aspx文件重构Javascript代码
我正在重构web项目,其中java脚本和css代码写在.aspx文件中。现在我正在从aspx文件中删除java脚本和css代码,并在各自的css和js文件中维护这些代码以及它们在aspx文件中的引用 如果java脚本代码是在函数中的一个地方编写的,这对我来说是直截了当的。在示例代码中,并非所有java脚本代码都在函数中,有些脚本在div块中。我无法将这些脚本放在单独的文件中。此外,我是java脚本和web开发的新手,请帮助我这个从Aspx文件重构Javascript代码,javascript,html,asp.net,css,Javascript,Html,Asp.net,Css,我正在重构web项目,其中java脚本和css代码写在.aspx文件中。现在我正在从aspx文件中删除java脚本和css代码,并在各自的css和js文件中维护这些代码以及它们在aspx文件中的引用 如果java脚本代码是在函数中的一个地方编写的,这对我来说是直截了当的。在示例代码中,并非所有java脚本代码都在函数中,有些脚本在div块中。我无法将这些脚本放在单独的文件中。此外,我是java脚本和web开发的新手,请帮助我这个 <asp:Content ID="Content2" Con
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
-------code-----------
</script>
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm())
{%>
<%: Html.ValidationSummary(true) %>
<div class="formColWhole" style="width: 935px;">
<script type="text/javascript">
document.body.style.cursor = 'default';
document.forms[0].action = '<% = ViewData["RegisterPageUrl"].ToString() %>';
function IndicateProcessing() {
if (typeof (Page_ClientValidate) == 'function') {
if (Page_ClientValidate() == false) { return false; }
}
var cancelButton = document.getElementById("<% = buttonCancel.ClientID %>");
if (cancelButton != null) {
cancelButton.disabled = true;
}
document.body.style.cursor = 'wait';
return true;
}
function submitForm() {
IndicateProcessing();
// _gaq.push(['_trackEvent', 'Register', 'Register submit Click', 'Register submit']);
// avoid duplicate submission
var button = $("#buttonSend");
button.attr('disabled', true).html('');
document.forms[0].submit();
}
</script>
</div>
<div class="formColWhole" style="width: 100%;">
--------code----
</div>
<script type="text/javascript">
var selectCountryText = document.getElementById("<% = selectCountry.ClientID %>").value;
var regions = document.getElementById("region");
regions.firstChild.text = selectCountryText;
</script>
</asp:Content>
-------代码--------
document.body.style.cursor='default';
document.forms[0]。操作=“”;
函数指示处理(){
if(typeof(Page_ClientValidate)==“函数”){
如果(Page_ClientValidate()==false){return false;}
}
var cancelButton=document.getElementById(“”);
如果(取消按钮!=null){
cancelButton.disabled=true;
}
document.body.style.cursor='wait';
返回true;
}
函数submitForm(){
指示处理();
//_gaq.push([“跟踪事件”、“注册”、“注册提交单击”、“注册提交”);
//避免重复提交
var按钮=$(“#按钮发送”);
button.attr('disabled',true).html('';
document.forms[0]。提交();
}
--------代码----
var selectCountryText=document.getElementById(“”)值;
var regions=document.getElementById(“region”);
regions.firstChild.text=选择CountryText;
您可以将嵌入的字段复制到一个空白页面中,并对其进行ajax/解析,也可以在主视图中打印少量配置。其他任何东西都可能需要重新分解。你所说的“嵌入字段到空白页”是什么意思?我的意思是你复制当前页面,但去掉所有其他HTML,除了嵌入的变量、无导航、无脚本标记等。然后你可以从任何地方获取嵌入的数据,而不必位于特定页面上。。。