如何prevent另一个按钮的触发 [英] How to prevent the trigger of another button
问题描述
我在我的ASP.net页面如下:
I have the following in my ASP.net page:
<input type="text" placeholder="Search..." size="30" id="pageLink" />
<br />
<span id="imgGo" class="imgGo floatRight"></span>
JQuery的:
JQuery:
$('.imgGo').click(function () {
var strString = $("#pageLink").val()
var strSearch = "http://www.google.com/search=";
var url = strSearch + strString;
window.open(url, '_blank');
return false;
});
$("#pageLink").keyup(function (event) {
if (event.keyCode == 13 || event.which == 13) {
$(".imgGo").click();
}
});
当我输入在文本框中的东西,然后点击 imgGo
跨度它工作正常,但如果不是我打进去,我的搜索按钮,这是在其他面板被触发。
When I enter something in the textbox and click the imgGo
span it works fine but if instead I hit enter, my search button which is in another panels gets triggered.
我怎么能要么修改我的JQuery code,以确保不发生或添加code-背后确保 imgGo
只有当输入触发按钮pssed而 pageLink
文本框具有焦点?$ p $
How can I either modify my JQuery code to ensure that doesn't happen or add code-behind to ensure imgGo
is triggered only if enter button is pressed while the pageLink
textbox has the focus?
我尝试以下,但没有工作,因为 imgGo
不是一个按钮:
I tried the following but didn't work because imgGo
is not a button:
<asp:Panel ID="pnlMedSearch" runat="server" DefaultButton="GoImg">
<!--<input type="text" placeholder="Search..." size="30" id="p2" />-->
<asp:TextBox Width="30" ID="pageLink" runat="server" />
<br />
<!--<span id="imgGo" class="imgGo floatRight"></span>-->
<asp:Label ID="imgGo" CssClass="imgGo floatRight" runat="server" />
</asp:Panel>
我收到以下错误:
I get the following error:
The DefaultButton of 'pnlMedSearch' must be the ID of a control of type IButtonControl.
我想使用文本框而不是ASP.net控制,因为占位符
属性是在我的情况很重要。
I would like to use the textbox which is not a ASP.net control because the placeholder
attribute is important in my case.
推荐答案
我保持相同的HTML内容,并修改了我的Jquery为以下内容:
I kept the same HTML content and modified my Jquery to the following:
$("#medlineSearch").keypress(function (event) {
if (event.which == 13) {
$("#imgGo").click();
return false;
}
});
添加返回false;
确保它没有调用页面上任何其他
Adding the return false;
ensure it didn't invoke anything else on the page.
这篇关于如何prevent另一个按钮的触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!