0

我正在使用这个片段:

onmouseover="this.title=this.options[this.selectedIndex].title"

这样我就可以在下拉菜单文本中添加标题标签。

<form name="searchform" onmouseover="this.title=this.options[this.selectedIndex].title" onsubmit="return doSearch();" accept-charset="', $context['character_set'], '">
<input class="search_input" type="text" name="search" value="" />
<input class="search_button" type="submit" name="submit" value="" />
<select class="search_select" name="sengines" onchange="return saveOption();">
<option value="?action=search2;search=" title="Full forum search">Forum</option>

使用浏览器工具检查时出现的错误是

Uncaught TypeError: Cannot read property 'undefined' of undefined at HTMLFormElement.onmouseover 
4

1 回答 1

0

在这种情况下,您需要绑定事件监听器的功能

<form name="searchform" onmouseover="function(this)" onsubmit="return doSearch();" accept-charset="', $context['character_set'], '">

这意味着当前标签/元素将通过事件的参数传递

 onmouseover="function(this)"

那么你在你想要的元素中添加事件,或者像你一样访问孩子

this.options[this.selectedIndex].title
于 2019-03-09T15:27:49.990 回答