关于Uncaught TypeError: Cannot read property 'toLowerCase' of undefined的问题

来源:互联网 发布:access数据库怎么做 编辑:程序博客网 时间:2024/05/22 00:32

今天我在处理表单时根据触发事件动态获取input中的value值,我是直接在html代码中设置响应函数,函数中用jquery的$(this).val()获取对象的value,结果控制台报出如标题所示的错误,这我就纳了闷了,怎么会这样,甚是纠结,上网一查排在前的相关问题都是stackoverflow的,找了几个看了下,好像不是我的这种情况,然后就各种尝试….

最后突然想到会不会连input这个节点对象没获取到啊,一试还真的是,于是我就换了("input[name=example]")jquery(this)在input这出了点状况。

html:

<script type="text/javascript">function check(){            console.log($(this));            $(this).attr("style","border:1px red solid");            console.log($(this).val());            // console.log($("input[name='example']"));       //$("input[name='example']").attr("style","border:1px red solid");            // console.log($("input[name='example']").val());        }</script></head><body>    <input type="text" name="example" value="0" onchange="check()"></body>

wrong:
这里写图片描述
right:
这里写图片描述

0 0
原创粉丝点击