
<!doctypehtml>
<html>
<head>
<metacharset="UTF-8">
<metaname="Generator"content="EditPlus®">
<metaname="Author"content="zzp">
<metaname="keywords"content="事件,函数,绑定,焦点,的话">
<metaname="description"content="<!doctypehtml><html><head><metacharset="UTF-8"><metaname="Generator"conte">
<title>Document</title>
<styletype="text/css">
input:focus,textarea:focus{
border:1pxsolid#f00;
background:#fcc;
}
focus{
border:1pxsolid#f00;
background:#fcc;
}
</style>
<scripttype="text/javascript"src="js/jquery-164minjs"></script>
<scripttype="text/javascript">
vartemp;
$(function(){
$(":input")focus(function(){//获得焦点
alert(thisid);
alert("获得焦点时的值是:"+(this)val());temp=trim((this)val());alert(temp);(this)addClass("focus");//添加样式
})blur(function(){//失去焦点
(this)removeClass("focus");//移除样式alert("失去焦点时的值是:"+(this)val());
varlastValue=trim((this)val());
if(temp!=lastValue&&null!=lastValue&&""!=lastValue)
{
alert("值改变了!");
}
else{
alert("值没有变!");
}
//
});
});
</script>
</head>
<body>
<formaction="#"method="post"id="reFrom">
<fieldset>
<legend>个人信息</legend>
<div>
<label>名称:</label>
<inputid="username"type="text"value="admin">
</div>
<div>
<label>密码:</label>
<inputid="pass"type="text"value="123456">
</div>
<div>
<label>性别:</label>
<inputid="sex"name="sex"type="radio"value="1"checked="checked">男
<inputid="sex"name="sex"type="radio"value="2">女
</div>
<div>
<label>详细信息:</label>
<inputid="msg"type="text"value="获取值">
</div>
</fieldset>
</form>
</body>
</html>
扩展资料
change()函数用于为每个匹配元素的change事件绑定处理函数。该函数也可用于触发change事件。此外,你还可以额外传递给事件处理函数一些数据。change事件会在文本内容或选项被更改时触发。该事件仅适用于和以及。
对于text和textarea元素,该事件会在元素失去焦点时发生(文本内容也发生了更改)。可以为同一元素多次调用该函数,从而绑定多个事件处理函数。触发change事件时,jQuery会按照绑定的先后顺序依次执行绑定的事件处理函数。要删除通过change()绑定的事件,请使用unbind()函数。该函数属于jQuery对象(实例)。
在JQuery中,当给radio添加一个change事件时,如果它的值发生变化就会触发change事件。
HTML中写入下代码:
<input type="checkbxo" id="testCheckbox" onchange="myfunction()"name="fruits">JQuery的代码如下:
$(document)ready(function(){$("testCheckbox")change(function() {
alert("Option changed!");
});
});
没看到input 有这种写法,你可以这样,
<input type="radio" name="appointmentRadio" value="1"><span>aa</span>
<input type="radio" name="appointmentRadio" value="2"><span>bb</span>
选择了一个radio那么文本值就是$(":radio:checked + span")text();
你自己都写出来了啊!取值直接用$("xxx input[name='name']")val();或者下拉框用select
监视的话你可以给div下的控件添加一个onchange事件。在他们改变后可以得到他们改变后的值
够呛。如果我做的话每道题肯定有一个div的,类似
<div class='question'><strong>问题</strong><br /><ul>
<li><input type="radio" name="q1" value='a' />答案A</li>
</ul>
</div>
然后js是
$('divquestion')each(function(){
if($(this)find('input:checked')length > 0) {
radio_valuepush($(this)find('input:checked:first')val());
} else {
radio_valuepush("no value");
}
});
以上就是关于jquery怎么判断输入框中的值是否改变全部的内容,包括:jquery怎么判断输入框中的值是否改变、jquery radio改变时没有触发on的change事件,是为什么、jquery 获取radio文本值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)