optionList = <span style="margin-left:1vh;">对象类型:</span><select style="margin-right:1vh;"> + optionList + </select>对象名称:<input type="text" style="border:1px solid #322f2f;" placeholder="请输入搜索关键词"><button>搜索</button>中给input标签添加onkeydown事件,当按下backspace键时,执行删除操作。
时间: 2023-08-14 17:26:28 浏览: 44
好的,你可以在input标签中添加onkeydown事件,当按下backspace键时,执行删除操作,代码如下:
```
<input type="text" style="border:1px solid #322f2f;" placeholder="请输入搜索关键词" name="search" onkeydown="if(event.keyCode==8){document.getElementsByName('search')[0].value=''}">
```
这样,当用户在input标签中按下backspace键时,会触发onkeydown事件,判断keyCode是否等于8(backspace键的keyCode是8),如果是,则将input标签的value值设置为空,实现删除效果。
相关问题
optionList = `<span style="margin-left:1vh;">对象类型:</span><select style="margin-right:1vh;">` + optionList + `</select>对象名称:<input type="text" style="border:1px solid #322f2f;" placeholder="请输入搜索关键词"><button>搜索</button>`中input删除键不能使用
这个问题的原因可能是因为你没有为input标签添加name属性,或者name属性值为空。请确保你的input标签有正确的name属性,例如:name="search",这样就可以使用删除键了。另外,你也可以使用JavaScript代码来实现删除键的功能,例如:给input标签添加onkeydown事件,当按下backspace键时,执行删除操作。
div class="qml-stem"><p style=""><span style="font-family: 宋体;">读一读,猜一猜。</span></p><p style=""><span style="font-family: 宋体;">什么鸟跑得快,不爱树林爱沙漠?(<span style="font-family: 'Times New Roman'" qml-space-size="2"> </span>)</span></p><div class=" qml-og"><table class="qml-og" style="width:100%"><tr><td>A. <span class="qml-op"><span style="font-family: 宋体;">山椒鸟</span></span></td><td>B. <span class="qml-op"><span style="font-family: 宋体;">鸵鸟</span></span></td><td colspan="1">C. <span class="qml-op"><span style="font-family: 宋体;">犀鸟</span></span></td></tr></table></div></div> 这段html中使用正则判断是否有选项A
可以使用以下正则表达式进行匹配:
```python
import re
html = '<div class="qml-stem"><p style=""><span style="font-family: 宋体;">读一读,猜一猜。</span></p><p style=""><span style="font-family: 宋体;">什么鸟跑得快,不爱树林爱沙漠?(<span style="font-family: \'Times New Roman\'" qml-space-size="2"> </span>)</span></p><div class=" qml-og"><table class="qml-og" style="width:100%"><tr><td>A. <span class="qml-op"><span style="font-family: 宋体;">山椒鸟</span></span></td><td>B. <span class="qml-op"><span style="font-family: 宋体;">鸵鸟</span></span></td><td colspan="1">C. <span class="qml-op"><span style="font-family: 宋体;">犀鸟</span></span></td></tr></table></div></div>'
match = re.search(r'<td>A\.(.*?)</td>', html)
if match:
option_a = match.group(1)
print(option_a) # 输出:山椒鸟
else:
print('没有选项A')
```
该正则表达式的含义是匹配 `<td>` 标签中以大写字母 A 开头,以 `</td>` 结尾的内容(即选项 A)。使用 `re.search()` 函数可以在字符串中搜索第一个匹配项。如果找到了匹配项,则使用 `match.group(1)` 获取第一个匹配的子串,即选项 A 的内容。如果没有找到匹配项,则说明没有选项 A。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)