【手机UI】搜索输入框,呼出软键盘时右下角为搜索按钮,并使用js发送请求

<!DOCTYPE html>
<html>
<head>
<title>搜索</title>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
</head>

<body>
	<form action="" method="get" id="J_search_artical" enctype='application/json'>
		<input type="search" id="J_search_content" placeholder="搜索" />
	</form>
</body>
<script>
window.onload = function(){
	document.getElementById("J_search_artical").onsubmit = function () {
		var title = document.getElementById("J_search_content").value;
		alert('title:'+ title);
		document.getElementById("J_search_content").blur()
		// do search
		return false;
		
	};
}
</script>
</html>


1 使用form表单

2 form表单action填空,使用js发送请求

3 form上增加enctype='applicaion/json'

4 点击搜索按钮的时候,会触发onsubmit事件

5 添加return false,屏蔽form表单会自动触发提交刷新页面的事件

转载于:https://www.cnblogs.com/snow-finland/p/7391127.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这是一个比较典型的聊天室排版,您可以按照以下步骤实现: 1. 首先安装 Taro 和 TypeScript: ```bash npm install -g @tarojs/cli npm install --save-dev typescript @types/react @types/react-native ``` 2. 创建一个新的 Taro 项目: ```bash taro init myApp ``` 3. 在 Taro 项目中安装需要的 UI 库,比如 Taro UI: ```bash npm install taro-ui ``` 4. 在页面组件中编写聊天室排版的代码,例如: ```tsx import Taro, { useState, useEffect } from '@tarojs/taro' import { View, Input, Button } from '@tarojs/components' import { AtMessage } from 'taro-ui' import './index.scss' interface Message { id: string, content: string, isSelf: boolean, } export default function Index() { const [inputValue, setInputValue] = useState('') const [messages, setMessages] = useState<Message[]>([]) useEffect(() => { Taro.onKeyboardHeightChange(handleKeyboardHeightChange) return () => { Taro.offKeyboardHeightChange(handleKeyboardHeightChange) } }, []) const handleKeyboardHeightChange = (event: Taro.onKeyboardHeightChange.CallbackResult) => { // 处理键盘高度变化事件 } const handleInputValueChange = (event: any) => { setInputValue(event.target.value) } const handleSendMessage = () => { if (inputValue.trim() === '') { Taro.atMessage({ message: '请输入消息内容', type: 'warning', }) return } const newMessage: Message = { id: `${Date.now()}`, content: inputValue, isSelf: true, } setMessages([...messages, newMessage]) setInputValue('') } return ( <View className="chat-room"> <AtMessage /> <View className="message-list"> {messages.map(message => ( <View key={message.id} className={`message-item ${message.isSelf ? 'self' : 'other'}`}> <View className="content">{message.content}</View> </View> ))} </View> <View className="input-bar"> <Input className="input-field" type="text" value={inputValue} placeholder="请输入消息内容" onInput={handleInputValueChange} /> <Button className="send-button" onClick={handleSendMessage}>发送</Button> </View> </View> ) } ``` 5. 在样式文件中定义聊天室排版的样式,例如: ```scss .chat-room { height: 100vh; display: flex; flex-direction: column; } .message-list { flex: 1; overflow-y: scroll; } .message-item { margin: 10px; max-width: 80%; padding: 10px; border-radius: 5px; } .self { align-self: flex-end; background-color: #87CEFA; } .other { align-self: flex-start; background-color: #F0E68C; } .input-bar { display: flex; flex-direction: row; align-items: center; padding: 10px; background-color: #F5F5F5; } .input-field { flex: 1; margin-right: 10px; } .send-button { width: 80px; } ``` 这样就完成了一个简单的聊天室排版的实现,其中包括了输入框和发送按钮在最下面,点击输入框弹起键盘,点击页面空白处键盘收起,自己发送的内容在页面边,他人发送的内容在页面左边等功能。当然,具体实现还需要根据实际需求进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值