使用jquery从li获取文本

使用jquery从li获取文本,jquery,Jquery,从javascript到jquery的转换。从li获取文本并使用jquery将其发送到input时出现问题-单击调用正常,但其余部分无效 HTML: 为什么这不起作用: $("#cssmenu li").click(function(li){ $("#ches").value = this.textContent;}) 而不是: $("#ches").value = this.textContent;} 使用: 不能在jQuery对象上使用value;改用.val()。试试这个,你需要使用

从javascript到jquery的转换。从li获取文本并使用jquery将其发送到input时出现问题-单击调用正常,但其余部分无效

HTML:

为什么这不起作用:

$("#cssmenu li").click(function(li){
$("#ches").value = this.textContent;})
而不是:

$("#ches").value = this.textContent;}
使用:

不能在jQuery对象上使用
value
;改用
.val()

试试这个,你需要使用

而不是

$("#ches").value = this.textContent;
$("#ches").value = this.textContent;}
$("#ches").val(this.textContent);
$("#ches").val(this.textContent);
 $("#ches").val($(this).text());
$("#ches").value = this.textContent;