1. 微信web开发 alert 能输入信息吗
alert('不能再减了');
}
});
$('#plus').click(function(){
var num=$('#cart_shopnum').val();
if(num<99){
num = num*1+1*1;
$('#cart_shopnum').val(num);
}else{
alert('不能再加了');
}
2. Javaweb项目里,写了一段ajax,case里的alert始终未触发是怎么回事
遇到问题时第一时间想到的应该是:调试。
先输出异步请求返回的msg的值,一下就能明白哪个环节出了问题。
3. 如何设置WebView支持js的Alert,Confirm,Prompt函数的弹出提示框
如何设置WebView支持js的Alert,Confirm,Prompt函数的弹出提示框
弹出提示框一般有3种
1)alert (普通提示框)
2)prompt (可输入的提示框)
3)confirm (可选择的提示框)
下面举个例子:
<!doctype html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title></head><body><button onclick="mal()">第一种:alert</button><button onclick="mpro()">第二种:prompt</button><button onclick="mcon()">第三种:confirm</button><script> function mal(){ alert('这是一个普通的提示框'); } function mpro(){ var val = prompt('这是一个可输入的提示框','这个参数为输入框默认值,可以不填哦'); //prompt会把输入框的值返回给你 } function mcon(){ var boo = confirm('这是一个可选择的提示框,3种提示方式,学会了吗?') //confirm 会返回你选择的选项,然后可以依据选择执行逻辑 if(boo){ alert('学会了,真聪明'); }else{ alert('再来一遍吧') } }</script></body></html>
4. 如何设置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);
5. java web中怎么实现javascript的alert功能
是在JSP页面中嵌入Jscript代码。
因为javascript是弱类型语言,只能在客户端运行的。
6. 如何设置WebView支持js的Alert,Confirm,Prompt函数的弹出提示框
如何设置WebView支持js的Alert,Confirm,Prompt函数的弹出提示框弹出提示框一般有3种1)alert(普通提示框)2)prompt(可输入的提示框)3)confirm(可选择的提示框)下面举个例子:Document第一种:alert第二种:prompt第三种:confirm
7. webbrowser中的alert,怎么自动点击。不要屏蔽。
下面这个方法是通用的,不能保证对你的这种情况一定适用。。。最好把alert周边的代码贴出来。。。
1.添加引用 mshtml
2.添加WebBrowser页面加载完毕的处理程序
=webbrowser1.document.docdocument
DomDocument.parentWindow.execScript("functionalert(s){returntrue;}","javaScript")
根据你的描述,修改如下:
=webbrowser1.document.docdocument
DomDocument.parentWindow.execScript("functionconfirm(s){return1;}","javaScript")
DomDocument.parentWindow.execScript("functionalert(s){returntrue;}","javaScript")
下面是我根据你的描述修改的网页代码,是否和你所说的类似。。。
<html>
<head>
<scripttype="text/javascript">
functionalert(s)
{
returntrue;
}
functionconfirm(s)
{
return1;
}
functionshow_confirm()
{
varr=confirm("Pressabutton!");
if(r==true)
{
alert("YoupressedOK!");
}
else
{
alert("YoupressedCancel!");
}
}
</script>
</head>
<body>
<inputtype="button"onclick="show_confirm()"value="Showaconfirmbox"/>
</body>
</html>
8. iOS js调webview的alert 为什么弹出来点击不了
原理是这样的,当alert弹出框点击确定以后,再让页面重新加载一下就可以,具体代码如下: <script type="text/javascript"> alert("提交成功!"); window.location.reload(); </script>