[英]How to perform two different action by using two ID's of textbox using one same button
In below textbox i have two different id's (ie 's' and 'primary-search-input') and only one button. 在下面的文本框中,我有两个不同的ID(即“ s”和“ primary-search-input”),并且只有一个按钮。
The first id(ie s) is a plugin id for performing search-suggestion work whenever the user enter any keyword he will get related suggestion. 第一个ID是插件ID,用于在用户输入任何关键字会获得相关建议时执行搜索建议工作。 And second id(ie primary-search-input) for getting the search keyword result when the user click on a button.
第二个id(即primary-search-input),用于在用户单击按钮时获取搜索关键字结果。
In the above case both id's has different different tasks. 在上述情况下,两个ID都有不同的不同任务。 when i put id='s' first and id='primary-search-input'second like below it will only perform first id action(ie get suggestion) and when i put id='primary-search-input' first and id='s'as a second position then it will only perform first id action(ie get keyword result on button click).
当我将id =的第一和id ='primary-search-input'第二,如下所示时,它将仅执行第一个id动作(即获得建议),当我将id ='primary-search-input'放在第一和id时=''作为第二个位置,那么它将仅执行第一个id操作(即,在单击按钮时获取关键字结果)。
My query is that how i can perform both the action at the same time like when user type any text into textbox he will get suggestion and also same time he click on button get keyword result on button click. 我的查询是,我如何同时执行两项操作,例如,当用户在文本框中输入任何文本时,他将获得建议,同时单击按钮时,也将在单击按钮时获得关键字结果。
<input name="s" id="s" id="primary-search-input" class="wide input" type="search" value="<?php if(isset($_GET['s']) && !isset($_GET['product'])) { echo sanitize_text_field(stripslashes(trim($_GET['s']))); } ?>" placeholder="<?php _e('I am shopping for...', 'framework')?>" />
<div id="primary-search-btn" class="medium primary btn"><a href="#"><i class="icon-search"></i></a></div>
You can't use multiple id in single input. 您不能在单个输入中使用多个ID。 From the XHTML 1.0 Spec
从XHTML 1.0 Spec
In XML, fragment identifiers are of type ID, and there can only be a single attribute of type ID per element. 在XML中,片段标识符的类型为ID,每个元素只能有一个类型为ID的属性。 Therefore, in XHTML 1.0 the id attribute is defined to be of type ID.
因此,在XHTML 1.0中,将id属性定义为ID类型。 In order to ensure that XHTML 1.0 documents are well-structured XML documents, XHTML 1.0 documents MUST use the id attribute when defining fragment identifiers on the elements listed above.
为了确保XHTML 1.0文档是结构良好的XML文档,在上面列出的元素上定义片段标识符时,XHTML 1.0文档必须使用id属性。 See the HTML Compatibility Guidelines for information on ensuring such anchors are backward compatible when serving XHTML documents as media type text/html.
有关确保在将XHTML文档作为媒体类型text / html提供服务时确保此类锚向后兼容的信息,请参见HTML兼容性指南。
You can only have one ID per element, but you can indeed have more than one class. 每个元素只能有一个ID,但实际上可以有多个类。 But don't have multiple class attributes, put multiple class values into one attribute.
但是没有多个类属性,请将多个类值放入一个属性中。
There can only be a single attribute of type ID per element. 每个元素只能有一个类型为ID的属性。 However you can use
data-* attributes
. 但是,您可以使用
data-* attributes
。 The data-* attributes
gives us the ability to embed custom data attributes on all HTML elements. data-* attributes
使我们能够在所有HTML元素上嵌入自定义数据属性。
You can have the HTML like this: 您可以使用如下所示的HTML:
<input name="s" id="s" data-id="primary-search-input" class="wide input" type="search" value="<?php if(isset($_GET['s']) && !isset($_GET['product'])) { echo sanitize_text_field(stripslashes(trim($_GET['s']))); } ?>" placeholder="<?php _e('I am shopping for...', 'framework')?>" />
<div id="primary-search-btn" class="medium primary btn"><a href="#"><i class="icon-search"></i></a></div>
You cannot use two id for an input. 您不能将两个id用作输入。 Id must be unique for a webpage.
网页的ID必须是唯一的。 I think you should need to do some toggle programming like that -
我认为您应该像这样进行一些切换编程-
<input type="button" id="s" value="" onclick="toggle()">
<script>
var flag = 0;
function toggle(){
if(flag == 0){
// do some work whatever you wanna do first
flag=1;
}else{
// Do some task whatever you wanna do next
flag = 0;
}
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.