Javascript 使用jquery突出显示弹出窗口的第一个输入元素
我有几个带有多个输入字段的弹出窗口。我想突出显示所有弹出窗口的第一个输入元素,但我不想使用ID: 我的代码:Javascript 使用jquery突出显示弹出窗口的第一个输入元素,javascript,jquery,html,jquery-mobile,Javascript,Jquery,Html,Jquery Mobile,我有几个带有多个输入字段的弹出窗口。我想突出显示所有弹出窗口的第一个输入元素,但我不想使用ID: 我的代码: function initPopups(){ $('*[id*=Popup]').each(function() { $(this).on({ // disables the auto close on outer clicks popupbeforeposition: function () {
function initPopups(){
$('*[id*=Popup]').each(function() {
$(this).on({
// disables the auto close on outer clicks
popupbeforeposition: function () {
// removes all handlers from the 'background'(-layer.class) of the popup
$('.ui-popup-screen').off();
},
// SHOULD highlight the first textfield after popup opened
popupafteropen:function(){
console.log("OPENED");
$('form:first *:input[type!=hidden]:first').focus();
}
});
});
以下是一个弹出窗口的html:
<div data-role="popup" id="create_stationPopup" class="ui-content">
<a href="#" data-rel="back" data-role="button" data-theme="c" data-icon="delete" data-iconpos="notext"
class="ui-btn-right">Close</a>
<form>
<input type="text" name="name" id="station_input_title" value="" data-mini="true" placeholder="Titel der Station" />
<input type="text" name="name" id="station_input_number" value="" data-mini="true" placeholder="Nummer der Station"/>
<textarea name="textarea" id="station_input_text" placeholder="Beschreibe diese Station"></textarea>
</form>
<a href="#create_stationQuestionPopup" data-rel="popup" data-role="button" data-theme="c" id="createWave_questionBtn" >Frage
hinzufügen</a>
<a id="createWave_stationSaveBtn" data-role="button" data-theme="c">Station
speichern</a>
</div>
站
斯皮切恩
“我的代码”仅突出显示HTML文件中的第一个输入字段,而不是所有弹出窗口中的第一个输入字段(静态HTML)尝试使用
[0]
选择表单中jQueryinput
元素的“数组”中的第一个元素:
popupafteropen:function(){
console.log("OPENED");
$('div[data-role=popup] input[type!=hidden]')[0].focus();
}
在@Trufa的帮助下,我用以下方式修复了它:
function initPopups(){
$('*[id*=Popup]').each(function() {
$(this).on({
popupbeforeposition: function () {
// removes all handlers from the 'background'(-layer.class) of the popup
$('.ui-popup-screen').off();
},
popupafteropen:function(){
$('.ui-popup-active *:input[type!=hidden]:first').focus();
}
});
});
}
每个弹出窗口在屏幕上都会显示类。ui弹出窗口处于活动状态
,因此只需使用它并突出显示第一个输入字段:)您使用的插件到底是什么,问题是它不清楚:(这是使用jQuery mobile吗?