如何使用jquery设置表单输入值?

发布于 2024-09-30 16:04:59 字数 398 浏览 1 评论 0原文

我试图为表单输入提供一个默认值,当用户单击输入框时该默认值会发生变化。

我怎样才能使用 jquery 做到这一点?

$(document).ready(function() {  
$('#tradition').click(function() {
$('#form-container').attr("class","trade");                         
$('.lblMadlib11').text("Eleven ");


$('.lblMadlib11a').val("eleven value field");


             });

我可以使用/将焦点添加到焦点上名为“lblMadlib11a”的字段的现有代码来删除默认值吗?

I am trying to give the form input a default value which changes when the user clicks on the input box.

How can I do this using jquery?

$(document).ready(function() {  
$('#tradition').click(function() {
$('#form-container').attr("class","trade");                         
$('.lblMadlib11').text("Eleven ");


$('.lblMadlib11a').val("eleven value field");


             });

Ho can I use / add focus to the existing code for the field called "lblMadlib11a" on focus to remove the default value.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光磨忆 2024-10-07 16:04:59

假设您有这样的输入文本:

<input id="username" type="text" value="insert your username">

您可以这样设置空值

$('#username').focus(function() {
  this.value="";
});

suppose you have an input text like this:

<input id="username" type="text" value="insert your username">

You could set empty value in this way

$('#username').focus(function() {
  this.value="";
});
清醇 2024-10-07 16:04:59
$('#inputbox').click(function() {

      this.attr('value', 'my new value')

});
$('#inputbox').click(function() {

      this.attr('value', 'my new value')

});
拥抱没勇气 2024-10-07 16:04:59
    $("#sometextid").bind('click',function(){
            $(this).attr('value',"somevalue");
    })
    $("#sometextid").bind('click',function(){
            $(this).attr('value',"somevalue");
    })
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文