在asp.net中如何在js中弹出对话框
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在asp.net中如何在js中弹出对话框相关的知识,希望对你有一定的参考价值。
在asp.net中点击客户端的超链接然后弹出上传控件的对话框
<asp:FileUpload ID="FileUpload1" runat="server" />
<a href="#" onclick="myclick()">弹出对话框</a>点击弹出对话框这几个字就弹出上次控件的对话框
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<style>
bodyfont-size:12px;font-family:verdana;margin:0;padding:0;background-color:#FAFDFF;
a color:#0365BF; text-decoration: none;
a:hover color:#f60; text-decoration: underline;
a.addfilebackground:url(images/others/addfile.gif) no-repeat;display:block;float:left;height:20px;margin-top:-1px;position:relative;text-
decoration:none;top:0pt;width:80px;cursor:pointer;
a:hover.addfilebackground:url(images/others/addfile.gif) no-repeat;display:block;float:left;height:20px;margin-top:-1px;position:relative;text-
decoration:none;top:0pt;width:80px;cursor:pointer;
input.addfilecursor:pointer;height:20px;left:-10px;position:absolute;top:0px;width:1px;filter:alpha(opacity=0);opacity:0;
#dv_fileinput_listfont-size:12px;font-family:verdana;
#dv_fileinput_msgfont-size:12px;font-family:verdana;
</style>
<head>
<script language="javascript">
<!--
/*改进的上传界面 HxyMan 2008-1-22*/
var DvFileInput=
$:function(d)return document.getElementById(d);,
isFF:function()var a=navigator.userAgent;return a.indexOf(\'Gecko\')!=-1&&!(a.indexOf(\'KHTML\')>-1||a.indexOf(\'Konqueror\')>-1||a.indexOf
(\'AppleWebKit\')>-1);,
ae:function(o,t,h)if (o.addEventListener)o.addEventListener(t,h,false);else if(o.attachEvent)o.attachEvent(\'on\'+t,h);elsetryo[\'on\'+t]=h;
catch(e);,
count:0,
realcount:0,
uped:0,//今天已经上传个数
max:1,//还可以上传多少个
once:1,//最多能同时上传多少个
boardid:0,
uploadcode:0,
readme:\'\',
add:function()
if (DvFileInput.chkre())
DvFileInput_OnEcho(\'<font color=red><b>您已经添加过此文件了!</b></font>\');
else if (DvFileInput.realcount>=DvFileInput.max)
DvFileInput_OnEcho(\'<font color=red><b>您最多只能上传\'+DvFileInput.max+\'个文件。</b></font>\');
else if (DvFileInput.realcount>=DvFileInput.once)
DvFileInput_OnEcho(\'<font color=red><b>您一次最多只能上传\'+DvFileInput.once+\'个文件。</b></font>\');
else
DvFileInput_OnEcho(\'<font color=blue>可以继续添加附件,也可以立即上传。</font>\');
var o=DvFileInput.$(\'dv_fileinput_\'+DvFileInput.count);
++DvFileInput.count;
++DvFileInput.realcount;
DvFileInput_OnResize();
var oInput=document.createElement(\'input\');
oInput.type=\'file\';
oInput.id=\'dv_fileinput_\'+DvFileInput.count;
oInput.name=\'dv_fileinput_\'+DvFileInput.count;
oInput.size=1;
oInput.className=\'addfile\';
DvFileInput.ae(oInput,\'change\',function()DvFileInput.add(););
o.parentNode.appendChild(oInput);
o.blur();
o.style.display=\'none\';
DvFileInput.show();
,
chkre:function()
var c=DvFileInput.$(\'dv_fileinput_\'+DvFileInput.count).value;
for (var i=DvFileInput.count-1; i>=0; --i)
var o=DvFileInput.$(\'dv_fileinput_\'+i);
if (o&&o.value==c&&DvFileInput.realcount>0)return true
return false;
,
filename:function(u)
var p=u.lastIndexOf(\'\\\\\');
return (p==-1?u:u.substr(p+1));
,
show:function()
var oDiv=document.createElement(\'div\');
var oBtn=document.createElement(\'img\');
var i=DvFileInput.count-1;
oBtn.id=\'dv_fileinput_btn_\'+i;
oBtn.src=\'images/others/filedel.gif\';
oBtn.alt=\'删除\';
oBtn.style.cursor=\'pointer\';
var o=DvFileInput.$(\'dv_fileinput_\'+i);
DvFileInput.ae(oBtn,\'click\',function()
DvFileInput.remove(i);
);
oDiv.innerHTML=\'<img src="images/others/fileitem.gif" border="0" /> <font color=gray>\'+o.value+\'</font> \';
oDiv.appendChild(oBtn);
DvFileInput.$(\'dv_fileinput_show\').appendChild(oDiv);
,
remove:function(i)
var oa=DvFileInput.$(\'dv_fileinput_\'+i);
var ob=DvFileInput.$(\'dv_fileinput_btn_\'+i);
if(oa&&i>0)oa.parentNode.removeChild(oa);
if(ob)ob.parentNode.parentNode.removeChild(ob.parentNode);
if(0==i)DvFileInput.$(\'dv_fileinput_0\').disabled=true;
if(0==DvFileInput.realcount)DvFileInput.clear();else--DvFileInput.realcount;
DvFileInput_OnResize();
,
init:function()
var a=document;
a.writeln(\'<form id="dv_fileinput_form" name="dv_fileinput_form" action="savefile.asp?t=1&boardid=\'+DvFileInput.boardid+\'" target="_self"
method="post" enctype="multipart/form-data" style="margin:0;padding:0;"><input type="hidden" id="UploadCode" name="UploadCode"
value="\'+DvFileInput.uploadcode+\'" /><div id="dv_fileinput_formarea"><img src="images/others/fileitem.gif" width=6 height=6 border="0"
/> <a href="javascript:;">添加附件<input id="dv_fileinput_0" name="dv_fileinput_0" class="addfile" size="1" type="file" onchange="DvFileInput.add();" /></a>
<span id="dv_fileinput_upbtn"><a href="javascript:DvFileInput.send();">上传附件</a></span> <span id="dv_fileinput_msg"></span>
\'+DvFileInput.readme+\'</div></form></div><div id="dv_fileinput_show"></div>\');
,
send:function()
if (DvFileInput.realcount>0)
DvFileInput.$(\'dv_fileinput_\'+DvFileInput.count).disabled=true;
DvFileInput.$(\'dv_fileinput_upbtn\').innerHTML=\'上传中,请稍等..\';
DvFileInput.$(\'dv_fileinput_form\').submit();
else
alert(\'请先添加附件再上传。\');
,
clear:function()
for (var i=DvFileInput.count; i>0; --i)
DvFileInput.remove(i);
DvFileInput.$(\'dv_fileinput_form\').reset();
var o=DvFileInput.$(\'dv_fileinput_btn_0\');
if(o)o.parentNode.parentNode.removeChild(o.parentNode);
DvFileInput.$(\'dv_fileinput_0\').disabled=false;
DvFileInput.$(\'dv_fileinput_0\').style.display=\'\';
DvFileInput.count=0;
DvFileInput.realcount=0;
DvFileInput_OnResize=function()
var o=parent.document.getElementById("ad");
(o.style||o).height=(parseInt(DvFileInput.realcount)*16+18)+\'px\';
DvFileInput_OnUpload=function(iFtype,sExt,sOldName,sShowName,iDownid)
try
if (\'1\'==iFtype||\'2\'==iFtype)
parent.dvtextarea.insert(\'[upload=\'+sExt+\',\'+sOldName+\']\'+sShowName+\'[/upload]<br/>\');
else
parent.dvtextarea.insert(\'[upload=\'+sExt+\',\'+sOldName+\']viewFile.asp?ID=\'+iDownid+\'[/upload]<br/>\');
parent.Dvform.upfilerename.value+=(iDownid+\',\');
catch(e)
DvFileInput_OnEcho=function(str)
DvFileInput.$(\'dv_fileinput_msg\').innerHTML=str;
DvFileInput_OnMsgSuc=function(str)
DvFileInput_OnEcho(str);
DvFileInput.clear();
DvFileInput_OnMsgFail=function(str)
DvFileInput_OnEcho(str);
DvFileInput.clear();
DvFileInput_OnUpdateRndCode=function(str)
DvFileInput.$(\'UploadCode\').value=str;
//-->
</script>
</head>
<body>
<script language="javascript">
<!--
DvFileInput.boardid=\'31\';
DvFileInput.uploadcode=\'1442\';
DvFileInput.uped=parseInt(\'0\');
DvFileInput.max=parseInt(\'100\');
DvFileInput.once=parseInt(\'50\');
DvFileInput.readme=\'今天还可上传\'+DvFileInput.max+\'个<a style="CURSOR: help" title="论坛限制:一次\'+DvFileInput.once+\'个,一天100个,每个500K">(查看论坛限制)
</a>\';
DvFileInput.init();
DvFileInput_OnResize();
//-->
</script>
</body>
</html> 参考技术A 那就用js打开一个新页面,页面可以设置成多种个性化样式的,然在页面放置FileUpload控件 参考技术B 现在网页的安全系数都提高了,不允许通过js直接操作file,不过可以通过其他方式来实现,代码太多,我就不贴了,加我HI,我发给你
Android在Service中弹出对话框二
上一篇我也写了一篇弹窗的,但是经过测试,Android8.0之后用不了,所以改一下
Myservice.class
package com.nf.service; import android.app.AlertDialog; import android.app.AliasActivity; import android.app.Dialog; import android.app.Service; import android.content.DialogInterface; import android.content.Intent; import android.os.Binder; import android.os.Build; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.util.Log; import android.view.WindowManager; import android.widget.Toast; import java.sql.Time; import java.util.Objects; import java.util.Timer; import java.util.TimerTask; public class MyService extends Service { // 全局声明Handler private Handler mHandler; public MyService() { } // 创建一个服务 @Override public void onCreate() { super.onCreate(); mHandler = new Handler(Looper.getMainLooper()); } // 服务启动 @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i("MyServer", "服务启动了"); Timer timer = new Timer(); int n = 5 * 60 * 10; timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { // new Thread(new Runnable() { // @Override // public void run() { // Looper.prepare(); // // TODO: 2019/11/7 // AlertDialog.Builder builder = new AlertDialog.Builder(MyApp.getContext()); // builder.setTitle("提示"); // builder.setMessage("已经过去五分钟了 且行且珍惜"); // builder.setNegativeButton("明白了", null); // Dialog dialog = builder.create(); // dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); // dialog.show(); // Looper.loop(); // } // }).start(); mHandler.post(new Runnable() { @Override public void run() { // AlertDialog.Builder builder = new AlertDialog.Builder(MyApp.getContext()); // builder.setTitle("提示"); // builder.setMessage("已经过去五分钟了 且行且珍惜"); // builder.setNegativeButton("明白了", null); // Dialog dialog = builder.create(); // dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); // dialog.show(); Log.i("MyServer", "服务启动了"); showDialog(); } }); Log.i("MyServer", "五分钟了"); } }, 10000, n); return super.onStartCommand(intent, flags, startId); } private void showDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext()) .setIcon(android.R.drawable.ic_dialog_info) .setTitle("提示") .setMessage("已经五分钟过去了 时间不等人") .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); AlertDialog dialog = builder.create(); //设置点击其他地方不可取消此 Dialog dialog.setCancelable(false); dialog.setCanceledOnTouchOutside(false); //8.0系统加强后台管理,禁止在其他应用和窗口弹提醒弹窗,如果要弹,必须使用TYPE_APPLICATION_OVERLAY,否则弹不出 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Objects.requireNonNull(dialog.getWindow()).setType((WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY)); }else { Objects.requireNonNull(dialog.getWindow()).setType((WindowManager.LayoutParams.TYPE_SYSTEM_ALERT)); } dialog.show(); } // 服务销毁 @Override public void onDestroy() { Log.i("MyServer", "服务死了"); super.onDestroy(); } @Override public IBinder onBind(Intent intent) { // TODO: Return the communication channel to the service. return new MyBinder(); } class MyBinder extends Binder { /** * 获取Service的方法 * @return 返回PlayerService */ public MyService getService() { return MyService.this; } } }
MainActivty.class
package com.nf.service; import androidx.appcompat.app.AppCompatActivity; import android.content.ComponentName; import android.content.Intent; import android.content.ServiceConnection; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.IBinder; import android.provider.Settings; import android.widget.Toast; public class MainActivity extends AppCompatActivity { public Intent intent; ServiceConnection serviceConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { // 建立连接 // 获取服务操作对象 MyService.MyBinder binder = (MyService.MyBinder) service; binder.getService();//获取到Service } @Override public void onServiceDisconnected(ComponentName name) { } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); intent = new Intent(this, MyService.class); startService(intent);//启动服务 checkMyPermission(); } @Override protected void onDestroy() { super.onDestroy(); // stopService(intent); // 程序销毁时,退出服务 } private void checkMyPermission() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!Settings.canDrawOverlays(this)) { Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); startActivityForResult(intent, 1); } } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 1) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Settings.canDrawOverlays(this)) { Toast.makeText(this, "授权成功", Toast.LENGTH_SHORT).show(); } else { // SYSTEM_ALERT_WINDOW permission not granted... Toast.makeText(this, "未被授予权限,相关功能不可用", Toast.LENGTH_SHORT).show(); } } } } }
AndroidManifest.xml
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/><!--这行代码必须存在,否则点击不了系统设置中的按钮--> <uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />
<service android:name=".MyService" android:enabled="true" android:exported="true"></service>
急着去上班,不做解释了
以上是关于在asp.net中如何在js中弹出对话框的主要内容,如果未能解决你的问题,请参考以下文章