導航:首頁 > 編程語言 > js彈窗提示alert

js彈窗提示alert

發布時間:2023-04-16 11:57:54

js中用alert沒有顯示提示。

  1. returnfalse;這個放在alert("對不起,用戶名太短啦!")下面,注意放在大括弧裡面

2.alert("對不起,用戶名太短啦!")後面缺少;號

3.<input type="text"/>修改成<input type="text" id="username"/>

❷ 如何讓在js里點擊一個東西 彈出alert

div.onclick=function(){
alert(「」)
}

div就是你要點擊的,加一個 onclick事件就可以

❸ 如何設置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);

❹ 這是一個js的彈窗,我想要知道調用alert的位置,如何做。跪求大神賜招。

雖然不同桌面主題會影響到彈窗格式,但有一點可以確認:題主所示圖片並非是一個alert彈窗。

下面這個是一個標準的alert彈窗(WIN 7系統默認主題)

如此就會影響到後續操作中出現的新提醒內容。

所以,通常網站內部提醒消息(如題主所給彈窗)是一個自定義彈窗,是JS生成的新dom元素,在該產生提醒時才顯示在網頁內。

因此不能通過查找alert來定位彈窗調用位置,而且也很難猜測自定義彈窗的方法名。

如果想查找該彈窗位置,建議在彈窗范圍內點右鍵,選擇「審查元素」,根據彈窗的class從js源代碼中查找包含該class的代碼段

❺ js:如何在alert彈出框,點擊確定以後再刷新頁面!

原理復是這樣的,當alert彈出框點制擊確定以後,再讓頁面重新載入一下就可以,具體代碼如下:

<scripttype="text/javascript">
alert("提交成功!");
window.location.reload();
</script>

❻ javascriptalert彈窗怎麼取消

1.
打開控制面板,進入Internet選項;
2.
在打開的Internet屬性窗口中,切換到【隱私】欄目;
3.
勾選【啟用彈出窗口阻止程序】選項,點擊【確定

❼ 怎麼修改js alert彈框樣式

那個改不了。只能覆蓋window.alert這個方法。
比如:你先去找個彈出框專的插件。(推薦一個:屬layer)
拿這個layer來舉例子:
提示消息的方法是:layer.msg
然後你可以用這個方法來覆蓋alert。
window.alert=layer.msg
然後你再是使用alert的時候 就會調用layer.msg了。

❽ 怎麼用js彈出提示框

彈出提示框一般有3種

1)alert (普通提示框)

2)prompt (可輸入的提示框)

3)confirm (可選擇的提示框)


下面舉個例子:

<!doctypehtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<title>Document</title>
</head>
<body>
<buttononclick="mal()">第一種:alert</button>
<buttononclick="mpro()">第二種:prompt</button>
<buttononclick="mcon()">第三種:confirm</button>
<script>
functionmal(){
alert('這是一個普通的提示框');
}

functionmpro(){
varval=prompt('這是一個可輸入的提示框','這個參數為輸入框默認值,可以不填哦');
//prompt會把輸入框的值返回給你
}

functionmcon(){
varboo=confirm('這是一個可選擇的提示框,3種提示方式,學會了嗎?')
//confirm會返回你選擇的選項,然後可以依據選擇執行邏輯
if(boo){
alert('學會了,真聰明');
}else{
alert('再來一遍吧')
}
}
</script>
</body>
</html>
閱讀全文

與js彈窗提示alert相關的資料

熱點內容
motoxt800刷機教程 瀏覽:591
有了中標文件單價該如何審計結算 瀏覽:57
港版蘋果616G多少錢最新報價 瀏覽:6
揭陽學編程哪個好 瀏覽:315
蘋果護眼壁紙 瀏覽:699
pcsx2按鍵配置文件 瀏覽:740
快賺鎖屏密碼忘了怎麼辦 瀏覽:849
後綴是acd是什麼文件 瀏覽:593
電腦無法打開視頻文件怎麼辦 瀏覽:904
如何簡化applewatch上的app 瀏覽:646
王者榮耀紫色字體代碼 瀏覽:186
surfacepro4系統版本 瀏覽:655
一加手機升級文件在哪個文件夾 瀏覽:537
u盤裝不了4g文件 瀏覽:740
豆神美育app怎麼退款 瀏覽:530
微信吃葯表情動態 瀏覽:425
網路廣播怎麼保存錄音 瀏覽:777
照片變漫畫ps教程 瀏覽:46
現在找不到王者cg文件 瀏覽:590
pdf文件怎麼編輯圖片要會員 瀏覽:303

友情鏈接