输入值后,用户点击'输入'表格被执行。但是,单击搜索图标时,没有任何反应。
图标是通过令人敬畏的字体库http://fontawesome.io/创建的 并通过css添加
content: '\f002';
这是代码的小提琴: https://jsfiddle.net/BamBamm/df2gzkbb/10/
我该如何解决这个问题?谢谢。
#search form {
text-decoration: none;
position: relative;
}
#search form:before {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-transform: none !important;
}
#search form:before {
-moz-transform: scaleX(-1);
-webkit-transform: scaleX(-1);
-ms-transform: scaleX(-1);
transform: scaleX(-1);
color: #7f888f;
content: '\f002';
cursor: default;
display: block;
font-size: 1.5em;
height: 2em;
line-height: 2em;
opacity: 0.325;
position: absolute;
right: 0;
text-align: center;
top: 0;
width: 2em;
}
input[type="text"] {
height: 2.75em;
}
input[type="text"] {
-moz-appearance: none;
-webkit-appearance: none;
-ms-appearance: none;
appearance: none;
background: #ffffff;
border-radius: 0.375em;
border: none;
border: solid 1px rgba(210, 215, 217, 0.75);
color: inherit;
display: block;
outline: 0;
padding: 0 1em;
text-decoration: none;
width: 100%;
}
body, input, select, textarea {
color: #7f888f;
font-family: "Open Sans", sans-serif;
font-size: 13pt;
font-weight: 400;
line-height: 1.65;
}

<link href="https://maxcdn.bootstrapcdn.com/font-awesome/3.1.0/css/font-awesome.min.css" rel="stylesheet" />
<div id="search" class="alt">
<form action="javascript:alert('Inner Function performed!');">
<input type="text" name="search_query" value="defaultValue"/>
</form>
</div>
&#13;
答案 0 :(得分:4)
您可以在提交按钮上添加图标
请检查该代码:
((Report)productionReport).Coils.Add(new a())
答案 1 :(得分:1)
您可以添加具有相同图标的提交按钮,而不是将图标放在表单中的伪元素上:
https://jsfiddle.net/df2gzkbb/12/
尽管这有效,但我建议你不要改变行为。在我看来通过点击图标发送表单会出现意外行为,从而恶化用户体验。
#search form {
text-decoration: none;
position: relative;
}
#search form button {
font-size: 0;
position: absolute;
right: 0;
top: 8px;
background-color: transparent;
border: 0;
appearance: none;
}
#search form button:before {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-transform: none !important;
-moz-transform: scaleX(-1);
-webkit-transform: scaleX(-1);
-ms-transform: scaleX(-1);
transform: scaleX(-1);
color: #7f888f;
content: '\f002';
cursor: default;
display: block;
font-size: 1.5rem;
height: 2rem;
line-height: 2rem;
opacity: 0.325;
text-align: center;
width: 2rem;
}
input[type="text"] {
height: 2.75em;
}
input[type="text"] {
-moz-appearance: none;
-webkit-appearance: none;
-ms-appearance: none;
appearance: none;
background: #ffffff;
border-radius: 0.375em;
border: none;
border: solid 1px rgba(210, 215, 217, 0.75);
color: inherit;
display: block;
outline: 0;
padding: 0 1em;
text-decoration: none;
width: 100%;
}
body,
input,
select,
textarea {
color: #7f888f;
font-family: "Open Sans", sans-serif;
font-size: 13pt;
font-weight: 400;
line-height: 1.65;
}
&#13;
<link rel="stylesheet" href="https://opensource.keycdn.com/fontawesome/4.7.0/font-awesome.min.css " />
<div id="search" class="alt">
<form action="javascript:alert('Inner Function performed!');">
<input type="text" name="search_query" value="defaultValue" />
<button type="submit">Search</button>
</form>
</div>
&#13;
答案 2 :(得分:1)
向DOM添加一个范围并向其添加一个事件:
$('#glyphicon').click(function(){
$('#myform').submit()
})
&#13;
#glyphicon {
position: relative;
left: -25px;
top: 6px;
background-image: url(http://wfarm4.dataknet.com/static/resources/icons/set110/37275f5a.png);
background-size : 100% 100%;
width: 20px;
height: 20px;
display: inline-block;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="search" class="alt">
<form id="myform" action="javascript:alert('Inner Function performed!');">
<input type="text" name="search_query" value="defaultValue"/>
<span id="glyphicon">
</span>
</form>
</div>
&#13;
答案 3 :(得分:1)
设置搜索按钮的onclick事件。 代码应该是这样的
<div onclick="myFunction()">
<i class="fa fa-minus-circle"></i>
</div>
表单将 Enter 键击作为提交。您必须为鼠标单击事件设置事件。