[英]javascript not seeing html after page load
我正在从具有基于工会类型的条件薪水报告的数据库中创建动态工作列表。 为了处理条件语句,我决定在cs页面的pageload部分中的构建数据集,以输出到aspx页面上的标签。 所有工作均按预期进行。 当我尝试在HTML上运行JQuery或Javascript以折叠并展开职位以显示要求时,就会出现问题。 使用JQuery,JS和Ajaxtookit有很多方法可以做到这一点。 所有这些在静态HTML上都像是一种魅力。 但是.Net在我的输出中添加了一个span标签,这会在布局中投入一把扳手,从而导致脚本无法正常工作。 然后,我添加了一个JQ函数以删除span标记,然后运行其他脚本(所有脚本都放置在页面底部,以便在加载页面后调用它们)。 Document.ready或window.load均无效。 看来页面加载和页面渲染状态可能是问题所在。 写入HTML后,如何让JQ和JS看到html? 谢谢
CS:
protected void Page_Load(object sender, EventArgs e)
{
String strConnString96 = WebConfigurationManager.ConnectionStrings["JobList_ConnectionString"].ConnectionString;
OleDbConnection con96 = new OleDbConnection(strConnString96);
OleDbCommand cmd96 = new OleDbCommand("SELECT * FROM JOBS WHERE (Status = 'Open') AND (Approved = 'Yes')", con96);
OleDbDataAdapter da96 = new OleDbDataAdapter(cmd96);
DataTable dtJobList = new DataTable();
da96.Fill(dtJobList);
con96.Close();
if (dtJobList == null || dtJobList.Rows.Count == 0)
lblJobList.Text = "<h3>No positions available at this time.</h3>";
if (dtJobList != null && dtJobList.Rows.Count > 0)
{
System.Text.StringBuilder sb1 = new System.Text.StringBuilder();
int i = 0;
foreach (DataRow row in dtJobList.Rows)
{
string JobTitle = row["Job_Title"].ToString();
string Func = row["Functions"].ToString();
string Qual = row["Qualifications"].ToString();
string ReqNum = row["Req_Number"].ToString();
string Low = row["Low_Range"].ToString();
string High = row["High_Range"].ToString();
string SalType = row["Salary_Type"].ToString();
string Union = row["Union"].ToString();
i++;
sb1.Append("<div id='JobNbr-" + i + "'><h4>" + JobTitle + "</h4><h5>Essential Functions</h5><p>" + Func + "</p><h5>Qualifications</h5><p>" + Qual + "<p>");
if (Union == "Executive" || Union == "Local 6" || Union == "C93")
{
sb1.AppendLine("<h5>Starting Salary</h5><p>" + Low + " - " + High + " <i>(" + SalType + ")</i>");
}
else
{
sb1.AppendLine("<h5>Starting Salary</h5><p>" + High + " <i>(" + SalType + ")</i>");
}
sb1.AppendLine("<a href='/HR_WebForm/HR_Form.aspx?Req_Number=" + ReqNum + "&Job_Title=" + JobTitle + "'><img src='/Resources/icons/apply.gif' alt='Apply' /></a></p></div>");
lblJobList.Text = sb1.ToString();
}
}
}
ASPX:
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolderMain" runat="server">
<h1>Employment</h1>
<div id="Employment">
<h2>Join New England's largest retail water & sewer provider!</h2>
<h2>How to Apply:</h2>
<ol><li>Submit your resume and cover letter online, please send attachments in PDF or Microsoft Word format, if not please fax to 617-989-7754 OR</li>
<li>Visit our Human Resources Department at 980 Harrison Avenue Boston, MA 02119</li></ol>
<p>We are located on several MBTA bus routes and visitors' parking is available on-site. Our office is open Monday through Friday, 8:00AM to 5:00PM.
</p>
<p>Come join our team!</p>
<h2>Current Openings</h2>
<div id="CurrentOpenings">
<a id="On" name="On" onclick="openAll('CurrentOpenings', 'h4','');" href="#_" class="hideIfNoJS">Open All</a>
<a id="Off" name="Off" onclick="closeAll('CurrentOpenings', 'h4','');" href="#_" class="hideIfNoJS">Close All</a>
<asp:Label ID="lblJobList" runat="server" Text="Label" />
</div>
<script>window.onload = "setCollapseExpand('CurrentOpenings', 'h4',''); revealControl('On'); revealControl('Off');"</script>
<script type="text/javascript" src="/JScode/expandcollapse.js"></script>
</asp:Content>
您正在将window.onload设置为字符串。
window.onload = "setCollapseExpand('CurrentOpenings', 'h4',''); revealControl('On'); revealControl('Off');"</script>
期待功能。 由于您已标记此jquery,因此请使用它。
$(window).on("load", function () {
setCollapseExpand('CurrentOpenings', 'h4','');
revealControl('On');
revealControl('Off');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.