使用val()方法修改value值:

$(".search").focus(function () {
    $(this).val("");//val()无法更改input标签里的value值,但是页面有效果
}).blur(function () {
    if ($("input").attr("value") == "") {
        $(this).attr({"value": "请输入要查询的问题"});
        /*$("input").attr("value","请输入要查询的问题");*/
    };
});

在这里插入图片描述

使用attr()方法修改value值:

$(".search").focus(function () {
    $(this).attr({"value": ""});//attr()可以更改input标签里的value值
}).blur(function () {
    if ($("input").attr("value") == "") {
        $(this).attr({"value": "请输入要查询的问题"});
    }
});

在这里插入图片描述

相关文章:

  • 2021-10-28
  • 2021-10-16
  • 2021-12-10
  • 2021-09-20
  • 2021-10-28
  • 2021-12-18
  • 2021-12-08
猜你喜欢
  • 2021-12-10
  • 2021-10-18
  • 2021-09-20
  • 2021-12-26
  • 2021-11-08
  • 2021-12-09
相关资源
相似解决方案