如何自动点击文本区域?

时间:2015-08-25 14:19:27

标签: javascript jquery

HTML代码

<textarea id="id1">
 Contents inside
</textarea>

Html 5

我们可以使用自动对焦直接点击textarea。但我想在不使用自动对焦的情况下实现。我们可以使用Jquery和Js。

任何想法?

3 个答案:

答案 0 :(得分:1)

试试这个 -

$(document).ready(function() {
  $('#id1').trigger('click');
});

答案 1 :(得分:0)

在文档的就绪功能中使用它:

$(function() {
    $('#id1').focus();
});

jQuery&#39; .focus方法以编程方式关注元素。

答案 2 :(得分:0)

试试这个

 foreach (DataRow dr in dt.Rows)
            {

                ++rowIndex;

                writer.WriteStartElement(new Row { RowIndex = rowIndex });

                for (int colInx = 0; colInx < numberOfColumns; colInx++)
                {
                    cellValue = dr.ItemArray[colInx].ToString();
                    cellValue = ReplaceHexadecimalSymbols(cellValue);
                    cellReference = excelColumnNames[colInx] + rowIndex.ToString();

                    // Create cell with data
                    if (IsIntegerColumn[colInx] || IsFloatColumn[colInx])
                    {
                        //  For numeric cells without any decimal places.
                        //  If this numeric value is NULL, then don't write anything to the Excel file.
                        cellFloatValue = 0;
                        bool bIncludeDecimalPlaces = IsFloatColumn[colInx];
                        if (double.TryParse(cellValue, out cellFloatValue))
                        {
                            cellValue = cellFloatValue.ToString(CultureInfo.InvariantCulture);
                            AppendNumericCell(cellReference, cellValue, bIncludeDecimalPlaces, writer);
                        }
                    }
                    else if (IsDateColumn[colInx])
                    {
                        //  For date values, we save the value to Excel as a number, but need to set the cell's style to format
                        //  it as either a date or a date-time.
                        DateTime dateValue;
                        if (DateTime.TryParse(cellValue, out dateValue))
                        {
                            AppendDateCell(cellReference, dateValue, writer);
                        }
                        else
                        {
                            //  This should only happen if we have a DataColumn of type "DateTime", but this particular value is null/blank.
                            AppendTextCell(cellReference, cellValue, writer);
                        }
                    }
                    else
                    {
                        //  For text cells, just write the input data straight out to the Excel file.
                        AppendTextCell(cellReference, cellValue, writer);
                    }
                }
                writer.WriteEndElement(); //  End of Row
            }

希望有所帮助