jQuery的VAL()方法的变化似乎并没有改变DOM [英] jQuery's val() method change doesn't seem to change the DOM

查看:453
本文介绍了jQuery的VAL()方法的变化似乎并没有改变DOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$(#someId)VAL(为newValue)不改变DOM。 -
我可以检索与 $(#someId),该值。VAL(),但在DOM元素仍然没有value属性。

Doing $("#someId").val("newValue") doesn't change the DOM -- I can retrieve this value with $("#someId").val(), but the element in the DOM still doesn't have a value attribute.

我如何设置输入组件的价值,改变它的DOM?

How do I set the value of an input component and also change the DOM?

我用的jQuery 1.5.1

推荐答案

.VAL()确实修改DOM。例如对于这样的:

.val() does change the DOM. For example this:

$("#someId").val("newValue");

alert(document.getElementById('someId').value);

提示为newValue。

alerts 'newValue'.

请参阅演示

如果你想改变的默认的在形式上采用重置价值,试试这个:

If you want to change the default value to be used in form resets, try this:

$("#someId").attr("defaultValue", "newValue");

请参阅演示

这篇关于jQuery的VAL()方法的变化似乎并没有改变DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆