本文目錄一覽:
- 1、asp.net如何在後台文件中編寫js
- 2、怎麼在後台加js代碼
- 3、在後台添加文章時,能不能添加進去JS代碼??
- 4、如何後台動態添加js腳本
- 5、asp.net如何在後台代碼中執行js
- 6、關於JS 代碼 如何在後台調用
asp.net如何在後台文件中編寫js
我暈~~~~~~ js文件是運行在前台的文件,你在後台怎麼可能產生js文件?
下面是在後台代碼中生成的隨機數字驗證碼
/// summary
/// 生成一個驗證碼
/// /summary
using System.Drawing;
using System.Drawing.Imaging;
private void CreateValidateCode()
{
using(Bitmap bitmap = new Bitmap(80, 24))
{
using(Graphics g = Graphics.FromImage(bitmap))
{
Random rand = new Random();
int code = rand.Next(1000, 9999);
string strcode = code.ToString();
g.DrawString(strcode, new Font(“宋體”, 18), Brushes.Red, 10, 0);
Session[“ValidateCode”] = strcode; //使用Session保存數字驗證碼
ImageButton1.ImageUrl = “source/1.jpg”; // 使用source文件夾下面的圖片 1.jpg
}
string abspath = System.Web.HttpContext.Current.Server.MapPath(@”source/1.jpg”); // 使用source文件夾下面的圖片 1.jpg, 作為輸出內存中的圖片的載體
bitmap.Save(abspath, ImageFormat.Jpeg);
}
}
怎麼在後台加js代碼
ScriptManager.RegisterClientScriptBlock(this, GetType(), “”, “js代碼”, true);
或者
ScriptManager.RegisterStartupScript(this, GetType(), “”, “js代碼”, true);
或者
Response.Write(“js代碼”)
在後台添加文章時,能不能添加進去JS代碼??
可以的,編輯的時候,轉到html方式編輯,將JS代碼寫進去,再轉到文本方式編輯內容就可以了。html方式編輯,還可以加超鏈接
如何後台動態添加js腳本
1
2
3
4
function loadJs(file) {
var head = $(“head”).remove(“script[role=’reload’]”);
$(“scri” + “pt” + “/scr” + “ipt”).attr({ role: ‘reload’, src: file, type: ‘text/javascript’ }).appendTo(head);
}
1
2
3
4
5
6
7
8
9
10
11
function reloadAbleJSFn(id,newJS){
var oldjs = null;
var t = null;
var oldjs = document.getElementById(id);
if(oldjs) oldjs.parentNode.removeChild(oldjs);
var scriptObj = document.createElement(“script”);
scriptObj.src = newJS;
scriptObj.type = “text/javascript”;
scriptObj.id = id;
document.getElementsByTagName(“head”)[0].appendChild(scriptObj);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
script type=”text/javascript” src=”../jquery.js”/script
script type=”text/javascript”
$(function()
{
$(‘#loadButton’).click(function(){
$.getScript(‘new.js’,function(){
newFun(‘”Checking new script”‘);//這個函數是在new.js裡面的,當點擊click後運行這個函數
});
});
});
/script
/head
body
button type=”button” id=”loadButton”Load/button
asp.net如何在後台代碼中執行js
把Page_load()事件裡面的btn.Attributes.Add(“onclick”, “opendialog(‘ShowDialog.aspx’)”);去掉
ClientScript.RegisterStartupScript(this.GetType(), “”, “scriptopendialog(‘ShowDialog.aspx’);/script”, true);
修改為:
ClientScript.RegisterStartupScript(this.GetType(), “aa”, “opendialog(ShowDialog.aspx)
“, true);試試…
關於JS 代碼 如何在後台調用
首先要保證js腳本是否載入完成。通過
Response.Write(“script type=”text/javascript” src=”ymPrompt/ymPrompt.js”/script”);
載入js。
調用則寫在後面
Response.Write(“script type=”text/javascript” ymPrompt.alert()/script”);
以上都是通過response的寫入頁面的方法做的。
最好還是通過跳轉頁面,用頁面的載入js腳本比較好控制
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/249416.html