jquery function val() is not equivalent to “$(this).value=”?

后端 未结 4 2139
礼貌的吻别
礼貌的吻别 2020-12-01 05:28

When I try to set a text input to blank (when clicked) using $(this).value=\"\", this does not work. I have to use $(this).val(\'\').

Why?

4条回答
  •  孤独总比滥情好
    2020-12-01 05:41

    $(this).value is attempting to call the 'value' property of a jQuery object, which does not exist. Native JavaScript does have a 'value' property on certain HTML objects, but if you are operating on a jQuery object you must access the value by calling $(this).val().

提交回复
热议问题