Javascript 要将一个jquery标记用于两个元素吗
我有两个输入类型文本,还有一个jquery选择器标记,现在我只能对一个元素使用它,我想对这两个元素都使用它Javascript 要将一个jquery标记用于两个元素吗,javascript,jquery,html,Javascript,Jquery,Html,我有两个输入类型文本,还有一个jquery选择器标记,现在我只能对一个元素使用它,我想对这两个元素都使用它 <form method="get" action="search.php"> <input type="text" name="search_text" class="h_input_one" placeholder="Type Here"> <input type="text" name="s_city" class="h_input_two" id="t
<form method="get" action="search.php">
<input type="text" name="search_text" class="h_input_one" placeholder="Type Here">
<input type="text" name="s_city" class="h_input_two" id="tags" placeholder="Select City">
<input type="submit" class="sub" value="">
</form>
};//jQuery Endid选择器返回第一个匹配项。向元素添加一个公共类,并改用类似$'.commonClass'的类选择器。您可以创建一个变量,该变量引用具有类属性的输入元素,其值设置为h_input_two,h_input_two;在删除重复的id=tagat元素后使用现有html
我有两个输入类型的文本,我有一个jquery选择器标记,现在我只能对一个元素使用它,我想对这两个元素都使用它。问题是,选择器标记在js的哪个位置使用?如果希望在同一个类别下标识多个元素,请使用“class”而不是“ID”。另外,我看不到你在代码中引用id标记的地方。我在type=text中调用了两次标记,@HarisFaraz id of element在文档中应该是唯一的。这是我的问题,我该怎么做。我唯一的目的是两个输入都将使用我的jquery代码,建议我如何实现它?非常感谢。
<form method="get" action="/city">
<input type="text" name="city" class="h_input_three" id="tags" placeholder="Select City">
<input type="submit" class="sub" value="">
</form>
$("a.topopup").hover(function() {
loading(); // loading
setTimeout(function(){ // then show popup, deley in .5 second
loadPopup(); // function show popup
}, 1); // .5 second
return false;
});
/* event for close the popup */
$("div.close").hover(
function() {
$('span.ecs_tooltip').show();
},
function () {
$('span.ecs_tooltip').hide();
}
);
$("div.close").click(function() {
disablePopup(); // function close pop up
});
$(this).keyup(function(event) {
if (event.which == 27) { // 27 is 'Ecs' in the keyboard
disablePopup(); // function close pop up
}
});
$("div#backgroundPopup").click(function() {
disablePopup(); // function close pop up
});
$('a.livebox').click(function() {
alert('Hello World!');
return false;
});
/************** start: functions. **************/
function loading() {
$("div.loader").show();
}
function closeloading() {
$("div.loader").fadeOut('normal');
}
var popupStatus = 0; // set value
function loadPopup() {
if(popupStatus == 0) { // if value is 0, show popup
closeloading(); // fadeout loading
$("#toPopup").fadeIn(0500); // fadein popup div
$("#backgroundPopup").css("opacity", "0.7"); // css opacity, supports IE7, IE8
$("#backgroundPopup").fadeIn(0001);
popupStatus = 1; // and set value to 1
}
}
function disablePopup() {
if(popupStatus == 1) { // if value is 1, close popup
$("#toPopup").fadeOut("normal");
$("#backgroundPopup").fadeOut("normal");
popupStatus = 0; // and set value to 0
}
}
/************** end: functions. **************/
<form method="get" action="search.php">
<input type="text" name="search_text" class="h_input_one"
placeholder="Type Here">
<input type="text" name="s_city" class="h_input_two"
placeholder="Select City">
<input type="submit" class="sub" value="">
</form>
<form method="get" action="/city">
<input type="text" name="city" class="h_input_three"
placeholder="Select City">
<input type="submit" class="sub" value="">
</form>
var inputs = $("input[class=h_input_two],input[class=h_input_three]")