![](/img/trans.png)
[英]Newbie to html, why isnt this code working? the Text isnt appearing properply?
[英]focus isnt working for text field
來源->
<input name="ctl00$MainContent$MapUserControl$6551_Edit_artintheparkssculpturelocations_32_id" type="text" maxlength="50" id="ctl00_MainContent_MapUserControl_6551_Edit_artintheparkssculpturelocations_32_id" onchange="MaxLength(50, this, 'id')" class="control-label form-control" id2="6551_Edit_artintheparkssculpturelocations_32_id">
我可以通過以下方式更新字段中的文本
x = document.getElementById('ctl00_MainContent_MapUserControl_6551_Edit_artintheparkssculpturelocations_32_id')
x.value ="bla";
但是我無法更新焦點...
x.focus();
返回未定義的預期值,但文本字段沒有任何反應。 我也嘗試過自動對焦,並用Jquery而不是JS來抓取元素。
曾經遇到過類似的問題。 您需要通過setTimeOut調用focus。
setTimeout(function() { x.focus()}, 1);
嘿,您需要使用以下代碼來觸發該事件
x.trigger('focus');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.