【问题标题】:How to focus textarea in this code如何在此代码中聚焦 textarea
【发布时间】:2016-02-13 11:28:21
【问题描述】:

fetch_customer_info.php

<button id=printToTextarea>Get to box</button>

text.php

<?php
require_once('fetch_customer_info.php');
?>
<script type="text/javascript">
$("#printToTextarea").on("click", function () {alert(3);
    $(this).next("#textInput").focus();
 });
 </script>

<div id="projectNameDiv">
    <label for="textInput">Text to Print:</label><br/>
    <textarea name="textInput" id="textInput"  rows='3' cols='40'></textarea>
</div>

当我单击“进入框”按钮时,没有出现警告消息。我需要关注文本区域。

【问题讨论】:

  • 显示 HTML 的其余部分。此外,您无需使用next(),因为您正在尝试查找id,只需使用$('#textInput').focus()
  • @powerbuoy 没用
  • 我不喜欢在单个文件中同时使用这两个部分。

标签: php html


【解决方案1】:

删除$(this).next()函数。

$("#printToTextarea").on("click", function () {
   alert(3);
   $("#text1").focus();
 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<textarea name="text1" id="text1" cols="30" rows="10"></textarea>
<button id="printToTextarea">Get to box</button>

【讨论】:

    猜你喜欢
    • 2019-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多