jquery焦点功能在iphone中不起作用

时间:2017-03-09 08:49:26

标签: javascript jquery html ios

我有一个要求,比如当我们从下拉列表中单击某个选项时,需要滚动到文本框。为了解决这个问题,我们在jquery中使用焦点功能,它在所有Android设备上工作正常,甚至在桌面ios中也可以,但在iphone 6中不起作用。请为此建议任何修复。

下拉html:

<select data-val="true" data-val-required="X Field is required." id="bnkdtls-mthd1" name="FinancialInformation.PreferredUsdAccount" onchange="validateusd();" aria-required="true" aria-describedby="bnkdtls-mthd1-error" class="valid" aria-invalid="false"><option value="">CHOOSE A METHOD</option>
    <option value="2">USD Wire Transfer</option>
    <option value="3">USD Check to Address</option>
</select>

jquery for change event

$("#bankdtls").on('change', '#bnkdtls-mthd1', function () {
    if ($(this).val() == "") {
        DisableUSDSection();
        DisablePrizeMoneySection();
    }
    if ($(this).val() == "2") {
        //DisablePrizeMoneySection();
        EnableUSDSection();
        $(".usdbnknm input").focus();
    }
    if ($(this).val() == "3") {
        DisableUSDSection();
        $(".przemnymladrs input").focus()
    }

});

目标textbot html:

<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 textbox1 paddinglftryt0 usdbnknm">
    <input class="textbox-input1 valid" id="FinancialInformation_UsdBankName" name="FinancialInformation.UsdBankName" onkeyup="validateUSDBankName();" type="text" value="bank" aria-invalid="false">
    <div class="valdtnerror-message" id="USDBankNamevaldtnID" style="display: none;">This field cannot be blank</div>
    <div class="valdtnerror-message" id="USDBankNamelenvaldtnID" style="display: none;">Bank Name cannot be more than 45 characters</div>
</div>

1 个答案:

答案 0 :(得分:1)

这是Safari吗?

关注&#39;聚焦&#39;在文本输入上:我很确定iOS默认阻止此行为。您必须手动点击输入,然后您将获得键盘左上角的up/down箭头以导航表单。

但是,如果输入位于屏幕上的其他位置,您可以将屏幕导航到正确的区域&#39;它居住在这样:

//scroll to the 'top' position (minus 30 for a bit of padding) 
//   of a given input over 1s
$("html, body").animate({ 
    scrollTop: $(".przemnymladrs input").offset().top-30 
}, 1000);