首页 > 编程知识 正文

后台写入js代码,引入js代码

时间:2023-12-28 11:56:51 阅读:327851 作者:ZPRS

本文目录一览:

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脚本比较好控制

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。