首页 > 代码库 > 动态生成JS

动态生成JS

 

           private void GenerateDrugAndProdJavaScript()            {                StringBuilder script = new StringBuilder();                script.Append("<script type=text/javascript>");                script.Append("function selectDrugAndProd(){");                script.Append("var drug = document.getElementById(‘" + hdnDrug.ClientID + "‘).value;");                script.Append("var productList = document.getElementById(‘" + hdnProduct.ClientID + "‘).value;");                script.Append("result = showModalDialogDisplay(‘../Dialog/DrugProdSelect.aspx?" + ConstValue.QUERY_STRING_KEY_SELECTED_DRUG_CODE + "=‘ + drug + ‘" + "&" + ConstValue.QUERY_STRING_KEY_SELECTED_PRODUCT_CODES + "=‘ + productList" + ", null, 650, 400);");                script.Append("if(result != null && typeof(result) == ‘object‘) {");                script.Append("document.getElementById(‘" + hdnDrug.ClientID + "‘).value = http://www.mamicode.com/result[0];");                script.Append("document.getElementById(‘" + txtDrug.ClientID + "‘).value = http://www.mamicode.com/result[1];");                script.Append("document.getElementById(‘" + hdnDrugName.ClientID + "‘).value = http://www.mamicode.com/result[1];");                script.Append("document.getElementById(‘" + hdnProduct.ClientID + "‘).value = http://www.mamicode.com/result[3];");                script.Append("document.getElementById(‘" + txtProduct.ClientID + "‘).value = http://www.mamicode.com/result[4];");                script.Append("document.getElementById(‘" + hdnProductName.ClientID + "‘).value = http://www.mamicode.com/result[4];");                script.Append("}");                script.Append("}");                script.Append("</script>");                Page.ClientScript.RegisterClientScriptBlock(typeof(string), "DrugAndProdJavaScript", script.ToString());            }
View Code

 

动态生成JS