導航:首頁 > 編程語言 > jsconfirm彈出框

jsconfirm彈出框

發布時間:2023-07-25 16:42:07

js 中confirm提示框的按鈕確定和取消變為是和否

下面這個方法可以將按鈕替換為「是」,「否」的形式,只支持IE
<script language=javascript>
function window.confirm(str)
{
execScript("n = (msgbox('"+str+"',vbYesNo, '提示')=vbYes)", "vbscript");
return(n);
}
alert(confirm("重載的confirm彈出框"));
</script>

❷ 怎麼用JavaScript實現自動點擊由confirm彈出的對話框中的「確定」按鈕

這個沒有搞過,但是可以給個思路:在頁面上添加下面的js試試,專即把js自己的alert、屬confirm、prompt給覆蓋掉。

varalert=function(){return1}
varconfirm=function(){return1}
varprompt=function(){return1}

❸ 如何設置WebView支持js的Alert,Confirm,Prompt函數的彈出提示框

默認情況下,Android WebView是不支持js的Alert(),Confirm(),Prompt()函數的彈出提示框的.即使設置了setJavaScriptEnabled(true);也是沒用的.那麼,如何才能讓WebView可以支持js的這3個函數呢.可以通過設置WebChromeClient對象來完成.WebChromeClient主要輔助WebView處理Javascript的對話框、網站圖標、網站title、載入進度等等.
這里主要重寫WebChromeClient的3個方法:
onJsAlert :警告框(WebView上alert無效,需要定製WebChromeClient處理彈出)
onJsPrompt : 提示框.
onJsConfirm : 確定框.
效果圖分別為:
1.Alert
2.Prompt
3.Confirm
先來看看js的頁面代碼:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<script type="text/javascript">
function call(){
var value = document.getElementById("input").value;
alert(value);
}
//警告
function onAlert(){
alert("This is a alert sample from html");
}
//確定
function onConfirm(){
var b = confirm("are you sure to login?");
alert("your choice is "+b);
}
//提示
function onPrompt(){
var b = prompt("please input your password","aaa");
alert("your input is "+b);
}
</script>
</head>
<body>
<input type="text" id="input" value="default"/>
<button onclick=call()>點我彈出Alert</button></br>
<input type="button" value="alert" onclick="onAlert()"/></br>
<input type="button" value="confirm" onclick="onConfirm()"/></br>
<input type="button" value="prompt" onclick="onPrompt()"/></br>
</body>
</html>
Android代碼:
package com.example.chenys.webviewdemo;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.TextView;
/**
* Created by mChenys on 2015/11/19.
*/
public class TestAlertActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView = new WebView(this);
setContentView(webView);
webView.requestFocus();
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);//啟用支持js
//設置響應js 的Alert()函數
webView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
AlertDialog.Builder b = new AlertDialog.Builder(TestAlertActivity.this);
b.setTitle("Alert");
b.setMessage(message);
b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
result.confirm();
}
});
b.setCancelable(false);
b.create().show();
return true;
}
//設置響應js 的Confirm()函數
@Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
AlertDialog.Builder b = new AlertDialog.Builder(TestAlertActivity.this);
b.setTitle("Confirm");
b.setMessage(message);
b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
result.confirm();
}
});
b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
result.cancel();
}
});
b.create().show();
return true;
}
//設置響應js 的Prompt()函數
@Override
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, final JsPromptResult result) {
final View v = View.inflate(TestAlertActivity.this, R.layout.prompt_dialog, null);
((TextView) v.findViewById(R.id.prompt_message_text)).setText(message);
((EditText) v.findViewById(R.id.prompt_input_field)).setText(defaultValue);
AlertDialog.Builder b = new AlertDialog.Builder(TestAlertActivity.this);
b.setTitle("Prompt");
b.setView(v);
b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String value = ((EditText) v.findViewById(R.id.prompt_input_field)).getText().toString();
result.confirm(value);
}
});
b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
result.cancel();
}
});
b.create().show();
return true;
}
});
webView.loadUrl("file:///android_asset/index3.html");
}
}
有2個需要注意的:
1.重寫onJsPrompt 方法,需要我們自定一個提示的布局文件,如下:prompt_dialog.xml
就是一個提示的TextView和輸入文本的EditTex而已.
[html] view plain
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/prompt_message_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/prompt_input_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="250dp"
android:selectAllOnFocus="true"
android:scrollHorizontally="true"/>
</LinearLayout>
2.WebView需要支持js的話,要記得加啟用js的支持.
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);

❹ javascript怎麼彈出一個確定框

javasc彈出一個確定框,主要是使用alert來彈出窗口,如下代碼:

if(window.confirm("確定刪除嗎?")){
$.get("../member/action.php?act=del",{snapID:id},
function(data){
if(data==1){
alert('success');//彈出成功的對話框
removeNode1(obj.parentNode.parentNode);
}else{
alert('error');//彈出錯誤提示的對話框
}
}

❺ js中用confirm("str")彈出的消息框怎麼設置按鈕的文本

沒辦法設置,那個文本是系統設定的,你用不同的操作系統可能會有所差別。
你要設置,你就用彈出層的方法。模擬出那樣的一個效果。

❻ js 中confirm的用法

confirm() 方法用於顯示一個帶有指定消息和OK 及取消按鈕的對話框。

如果用戶點擊確定按鈕,則confirm() 返回true。如果點擊取消按鈕,則confirm() 返回false。

在用戶點擊確定按鈕或取消按鈕把對話框關閉之前,它將阻止用戶對瀏覽器的所有輸入。在調用confirm() 時,將暫停對JavaScript 代碼的執行,在用戶作出響應之前,不會執行下一條語句。

下面我們通過這兩個小例子,來了解一下它的使用方法吧:

<html>
<head>
<title>confrim的使用方法</title>
<scripttype="text/javascript">
functionclear1()
{
if(confirm("確定要清空數據嗎?"))
{
document.main.text1.value="";
}
}
</script>
</head>
<boty>
<formname="main">
<inputtype="text"name="text1"/>
<inputtype="button"name="submit"value="數據清空"onclick="returnclear1()"/>
</form>
</body>
</html>

❼ javascript confirm用法

用法一:主要用於刪除單條信息確認。

<SCRIPT LANGUAGE=javascript>

function del() {

var msg = "您真的確定要刪除嗎? 請確認!";

if (confirm(msg)==true){

return true;

}else{

return false;

}

}

</SCRIPT>

調用方法:

<a href="del.php?id=123" onclick="javascript:return del()">刪 除</a>

用法二:原理跟用法一的一樣。JavaScript刪除確認框 。

<a href="javascript:if(confirm('確實要刪除嗎?'))location='jb51.php?id='">刪除</a>

用法三:主要用於批量刪除的確認提示 。

<input name="Submit" type="submit" class="inputedit" value="刪除"

onclick="{if(confirm('確定紀錄嗎?')){

this.document.formname.submit();

return true;}return false;

}">

<input name="按鈕" type="button" ID="ok" onclick="{if(confirm('確定刪除嗎?')){

window.location='Action.asp?Action=Del&

TableName=Item&

ID=<%=ID%>';

return true;

}return false;}"

value="刪除欄目" />

(7)jsconfirm彈出框擴展閱讀:

confirm參數message:

1、confirm()函數中的參數是確認框的提示語。

2、此函數返回值是布爾型的,點擊確定,返回值為true,點擊取消返回值為false。

3、confirm快速調用:

<a<a target

="_blank" href

="/item/href/7779531" data-lemmaid

="7779531">href</a>

="#"onclick

="returnconfirm('是否打開鏈接');"><inputtype

="button"value

="鏈接"/></a>

註:點擊鏈接後,在彈出對話方塊中,如果點擊「確定」那麼就進入超鏈接所連接的地址;如果點擊「取消」不執行鏈接。

閱讀全文

與jsconfirm彈出框相關的資料

熱點內容
網站設計編程如何開始學習 瀏覽:749
淘寶代碼隱藏導航不見了 瀏覽:7
macbookpro如何修改文件內容 瀏覽:965
java穩定排序 瀏覽:53
oppo文件管理的圖片 瀏覽:335
plc編程步數怎麼計算 瀏覽:142
ipad看電腦文件 瀏覽:935
成都製作pdf文件 瀏覽:735
怎麼樣點開電腦裡面的網路連接 瀏覽:755
微信怎麼退出賬號 瀏覽:32
w微信開發者工具 瀏覽:325
資料庫還原附加 瀏覽:713
打包成exe執行文件 瀏覽:652
信豐營銷app有哪些 瀏覽:463
蘋果文件下載項如何下載 瀏覽:179
ps摳婚紗教程 瀏覽:203
如何在移動硬碟上隱藏文件夾 瀏覽:451
瑞虎8老車機怎麼刷app 瀏覽:992
學ui設計要學java嗎 瀏覽:275
淘寶票房數據源怎麼調整 瀏覽:470

友情鏈接