You are somehow correct.
LINQ operates with IQueryable type, while jQuery operates with a jQuery :). Though IQueryable is much more abstract than jQuery object, in terms of data.
You misunderstood, however, the concept of what data is there which is non-jQuery. The jQuery object revolves around DOM objects, and only operates with them. Values may be passed and tossed around, but there has to be DOM, or jQuery is pointless. To compare, IQueryable was made to work with data, with values, or with objects. These are 2 totally different concepts, which only have some similar principle when working with them.
$(#mytxt)
should be $("#mytxt")
val()
returns a scalar, which is not jQuery, so you can t apply an event handler using select()
$(document).ready(callback)
syntax is kind of deprecated, use jQuery(callback)
instead, or just $(callback)
- I would advise you check the event, to see what key was pressed, so as not to resize the DOM element each time a key is pressed. You can pass an argument, i.e.
event
to the callback function, which will receive data about the event. event.which
would be the character code. For more info, visit this page
因此,您可以选择以下内容:
<script language="javascript" type="text/javascript">
$(function () {
$("#mytxt").keypress(function (event) {
if(event.which==13)
$(this).attr("rows", $(this).val().split("
").length );
});
});
</script>
请注意,val()
返回一个标量(一个通用的JavaScript字符串),从现在起与jQuery无关。split()
是一个用于字符串操作的JavaScript函数,length
也是一个用于测量数组长度的JavaScript属性。