输入对话框
[!TIP|labelVisibility:hidden|iconVisibility:hidden] navigator.notification.prompt(message, callback, title, buttonLabels, defaultText)
支持平台:
- Android
- iOS
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
message | String | 是 | 提示内容,默认 Prompt message |
callback | Function | 是 | 回调函数,可为null |
title | String | 是 | 标题文字,默认文字 Prompt |
buttonLabels | StringArray | 否 | 按钮文字数组,默认['OK','Cancel'] |
defaultText | String | 否 | 输入框里的默认文字 |
callback
函数返回值为一个对象,其属性包含以下两项:
input1
(String) -- 文本输入框里的文字内容buttonIndex
(Int) -- 点击按钮所对应的索引值
示例代码
// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
navigator.notification.prompt(
'You are the winner!',
function (results) {
console.log("You selected button number " + results.buttonIndex + " and entered " + results.input1);
},
'Registration',
['Restart','Exit'],
'Jane Doe'
);
}
</script>