jQuery .val更改不会更改输入值 [英] jQuery .val change doesn't change input value

查看:111
本文介绍了jQuery .val更改不会更改输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的HTML输入中包含值中的链接。

I have an HTML input with a link in the value.

<input type = 'text' value = 'http://www.link.com' id = 'link' />

我正在使用jQuery更改某个事件的值。

I am using jQuery to change the value on a certain event.

$('#link').val('new value');

上面的代码更改了文本框的值,但没有更改代码中的值( value ='http://www.link.com'保持不变)。我还需要值=''来改变。

The above code changes the value of the text box but doesn't change the value in the code (value = 'http://www.link.com' stays unchanged). I need the value = '' to change as well.

推荐答案

使用 attr 相反。

$('#link')。attr('value','new value');

演示

这篇关于jQuery .val更改不会更改输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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